gpt4 book ai didi

email - 构建失败时未发送 Jenkins 管道电子邮件

转载 作者:行者123 更新时间:2023-12-01 16:43:25 25 4
gpt4 key购买 nike

我在管道 Jenkins 作业中使用以下步骤:

step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'my@xyz.com', sendToIndividuals: true])

但是当构建失败(即错误)时,没有发送电子邮件。有什么指示吗?

附注可以从该服务器发送电子邮件,我已经测试过。

最佳答案

使用新语法的声明式管道,例如:

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: "foo@foomail.com";
}
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'
}
}
}

您可以在 Jenkins 官方网站中找到更多信息:

https://jenkins.io/doc/pipeline/tour/running-multiple-steps/

请注意,这种新语法使您的管道更具可读性、逻辑性和可维护性。

关于email - 构建失败时未发送 Jenkins 管道电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43721207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com