[英]How to add Job Description into Jenkins email notification content
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. 使用Jenkins中的“ 配置系统”>“扩展电子邮件通知”配置,我想将我的工作描述(在http://my-jenkins.org/job/myjob页面上显示)添加到构建失败电子邮件的默认内容中。
Is there any $PROJECT_DESCRIPTION variable that I can use for that ? 我可以使用任何$ PROJECT_DESCRIPTION变量吗? Or is it possible to do that using a Jelly/Groovy script ? 还是可以使用Jelly / Groovy脚本来做到这一点?
Thanks ! 谢谢 !
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'. 因为第一个条目之一包含一个名为“ description”的xml标记。 Parse it to a variable and then use to add to e-mail body via e-mail ext. 将其解析为变量,然后用于通过电子邮件扩展名添加到电子邮件正文中。
As told by Zloj , Jenkins don't have such variable but you can customize your own. 正如Zloj所说,詹金斯(Jenkins)没有这样的变量,但是您可以自定义自己的变量。 Jenkins have plugin to set Environment variables through a file by Jenkins有一个插件可以通过
Envfile Plugin Envfile插件
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 并将其保存在文件中,例如:/ tmp / ENV
If the content of description is "Hello world". 如果描述的内容是“ Hello world”。
cat /tmp/ENV
$PROJECT_DESCRIPTION=Hello World
Now add $PROJECT_DESCRIPTION in your e-mail 现在在您的电子邮件中添加$ PROJECT_DESCRIPTION
For Dynamically updated description I have a workaround for you until I find a better solution... create a shell script "wrapper.sh" 对于动态更新的描述,在找到更好的解决方案之前,我为您提供了一种解决方法...创建一个shell脚本“ 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. 该脚本动态创建您的env文件。
Now Install ManagedScript Plugin:- 现在安装ManagedScript插件:
Create a managed script file by following the above link with following content 通过使用上面的链接和以下内容创建托管脚本文件
sh /tmp/wrapper.sh
Now go to your project configuration:- 现在转到您的项目配置:
1). 1)。 Under Build option add "Execute managed script and select the one you created in previous step 在“生成”选项下,添加“执行托管脚本,然后选择您在上一步中创建的脚本”。
2). 2)。 apply and save. 申请并保存。
Voila. 瞧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.