不发送我使用下面的步骤在我的管道詹金斯的工作:詹金斯管线电子邮件上构建失败
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: '[email protected]', sendToIndividuals: true])
但是,当构建失败(即误差)没有电子邮件发送。任何指针为什么?
P.S.电子邮件可以从这个服务器发送,我已经测试过了。
不发送我使用下面的步骤在我的管道詹金斯的工作:詹金斯管线电子邮件上构建失败
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: '[email protected]', sendToIndividuals: true])
但是,当构建失败(即误差)没有电子邮件发送。任何指针为什么?
P.S.电子邮件可以从这个服务器发送,我已经测试过了。
您需要手动将生成结果设置为失败,并确保它在工作区中运行。例如:
try {
throw new Exception('fail!')
} catch (all) {
currentBuild.result = "FAILURE"
} finally {
node('master') {
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: '[email protected]', sendToIndividuals: true])
}
}
该插件检查currentBuild.result
的状态,这是不正常改变,直到脚本完成后。
使用声明管道使用新的语法,例如:
pipeline {
agent any
stages {
stage('Test') {
steps {
sh 'echo "Fail!"; exit 1'
}
}
}
post {
always {
echo 'This will always run'
}
success {
echo 'This will run only if successful'
}
failure {
mail bcc: '', body: "<b>Example</b><br>\n\<br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "ERROR CI: Project name -> ${env.JOB_NAME}", to: "[email protected]";
}
unstable {
echo 'This will run only if the run was marked as unstable'
}
changed {
echo 'This will run only if the state of the Pipeline has changed'
echo 'For example, if the Pipeline was previously failing but is now successful'
}
}
}
你可以找到在官方詹金斯网站的详细信息:
https://jenkins.io/doc/pipeline/tour/running-multiple-steps/
注意,这个新的语法让你的管道更可读,逻辑和可维护。
不幸的是,我正在使用Jenkins的旧版本(1.6.X)。 – saikosen
请检查我的答案在这里:http://stackoverflow.com/questions/36948606/jenkins-notifying-error-occured-in-different-steps-by-sending-mail-in-pipeline我认为你有相同的问题 –
确实检查了Jenkins主配置中的电子邮件设置,而不是作业 – Torsten