我编写了以下代码并想向用户发送电子邮件通知。但是我注意到有时会有“误报”报告。我只是想知道 Jenkins 声明式管道是否有一种方法允许我使用真实的执行状态来设置 currentBuild.result。(我想我应该使用currentBuild.result = 'SUCCESS'
or 'FAILURE'
)。例如,start_up.sh /mydata/test.json
可以将“SUCCESSFUL”或“ERROR”写入文件。如何根据该文件的内容将 currentBuild.result 分别设置为“SUCCESS”或“FAILURE”?非常感谢。
pipeline {
agent {
docker {
image ...
args ...
}
}
parameters {
string(name: 'E_USERNANE', defaultValue: 'githubuser', description: 'Please input the username')
string(name: 'E_BRANCH', defaultValue: 'dev', description: 'Please input the git branch you want to test')
}
stages {
stage('build') {
steps {
echo "username: ${params.E_USERNANE}"
echo "branch: ${params.E_BRANCH}"
sh """
...
start_up.sh /mydata/test.json
...
"""
}
}
}
post {
failure {
// notify users when the Pipeline fails
mail to: 'xxxi@gmail.com',
subject: "Failed Pipeline * ${currentBuild.fullDisplayName}",
body: "Something is wrong with ${env.BUILD_URL}."
}
success {
// notify users when the Pipeline succeeds
mail to: 'xxx@gmail.com',
subject: "Success Pipeline * ${currentBuild.fullDisplayName}",
body: "The build ${env.BUILD_URL} is passed!"
}
}
}