How to add Job Description into Jenkins email notification content

拟墨画扇 提交于 2019-12-24 03:37:25

问题


Using the Configure System > Extended E-mail Notification configuration in Jenkins I would like to add the description of my job (present on http://my-jenkins.org/job/myjob page) into the Default Content of build failure emails.

Is there any $PROJECT_DESCRIPTION variable that I can use for that ? Or is it possible to do that using a Jelly/Groovy script ?

Thanks !


回答1:


As told by Zloj , Jenkins don't have such variable but you can customize your own. Jenkins have plugin to set Environment variables through a file by
Envfile Plugin

Extract Description

grep -o '<description>.*</description>' /var/lib/jenkins/jobs/your_job_here/config.xml | sed 's/\(<description>\|<\/description>\)//g' 

And save it in a file for eg: /tmp/ENV

If the content of description is "Hello world".

cat /tmp/ENV
$PROJECT_DESCRIPTION=Hello World

Now add $PROJECT_DESCRIPTION in your e-mail

For Dynamically updated description I have a workaround for you until I find a better solution... create a shell script "wrapper.sh"

cat wrapper.sh

#!/bin/bash

echo "PROJECT_DESCRIPTION=`grep -o '<description>.*</description>' /var/lib/jenkins/jobs/your_job_here/config.xml | sed 's/\(<description>\|<\/description>\)//g'`" > /tmp/env

This script creates your env file Dynamically.

Now Install ManagedScript Plugin:-

Create a managed script file by following the above link with following content

sh /tmp/wrapper.sh    

Now go to your project configuration:-

1). Under Build option add "Execute managed script and select the one you created in previous step

2). apply and save.

Voila.




回答2:


There is no such environmental variable, but you can set it yourself:

${JENKINS_HOME}/jobs/${JOB_NAME}/config.xml

as one of the first entries contains an xml tag called 'description'. Parse it to a variable and then use to add to e-mail body via e-mail ext.



来源:https://stackoverflow.com/questions/32569138/how-to-add-job-description-into-jenkins-email-notification-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!