如果Jenkins' Build Passes'可以发送电子邮件。构建失败后?

时间:2017-08-03 08:39:04

标签: jenkins jenkins-plugins

如果Jenkins' Build Passes'可以发送电子邮件。构建失败后?

  1. 例如,我有x3版本失败
  2. 但第四次构建通过
  3. 是否可以发送电子邮件说构建已通过

1 个答案:

答案 0 :(得分:0)

您可以在Jenkins中使用shell脚本来实现它。

获取当前构建状态

CURRENT_BUILD_STATUS=$(curl --silent ${BUILD_URL}api/json | jq -r '.result')

获取上一个内部版本号

prevBuildNo=$(($BUILD_NUMBER-1))

echo $prevBuildNo

获取以前的构建状态

PREVIOUS_BUILD_STATUS=$(curl -- silent http://jenkins.org.com/jenkins/job/job/jobname/${prevBuildNo}/api/json | jq -r '.result)

如果先前的构建失败并且当前构建成功

,则进行清理

if ["$CURRENT_BUILD_STATUS" = "SUCCESS"] && ["$PREVIOUS_BUILD_STATUS" = "FAILED"] then #sending the mail echo $ echo "hello world" | mail -s "a subject" someone@somewhere.com else echo "No e-mail trigger as the previous build was successful." fi