我正在努力实现以下目标:
因此,考虑到所有这些,我开始尝试配置构建:
stage ('Serenity') {
steps {
// For the Delivery CI build don't fail on regression failure
sh 'mvn clean verify -pl regression -DskipCuke=false'
}
post {
always {
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true,
keepAll: true, reportDir: 'regression/target/site/serenity',
reportFiles: 'index.html', reportName: 'Serenity',
reportTitles: ''])
}
failure{
echo 'There are regression suite failures.'
script {
currentBuild.result = 'SUCCESS'
}
emailext attachLog: true, body: 'Find Attached',
compressLog: true, recipientProviders: [[$class:
'CulpritsRecipientProvider']], subject: 'Broken Regression Tests',
to: 'dennis@dennis.ru'
}
}
}
然而它不起作用,因为我无法将currentBuild.result
的值重置为'SUCCESS'。所以我可以|| true
命令mvn
,但这意味着我无法通过电子邮件发送有关破坏的回归测试的信息。
所以我想知道是否有其他人以某种聪明的方式解决了这个问题。我是否需要分配退出代码或其他内容,是否会涉及覆盖Jenkins中的默认shell参数?
任何帮助都非常感激。
答案 0 :(得分:1)
我认为你需要在shell中放置一个try / catch(所以在td=link_to 'Destroy', article_path(article), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger'
块中运行它),然后在catch中执行你的电子邮件。然后,您可以将构建集保持为SUCCESS。
答案 1 :(得分:1)
我实际上以与@ Rob的建议略有不同的方式解决了这个问题,但关键是理解我想要做的事情需要使用带有script
标志的returnStatus
块。我更喜欢这个尝试捕获,因为我实际上期望(不幸的是)这会不时失败,所以我更愿意在下面进行分支。
stage ('Serenity') {
steps {
script{
// For the Delivery CI build don't fail on regression failure
def bddPassed = ( sh ( returnStatus:true, script:'mvn clean verify -pl regression -DskipCuke=false') == 0 )
if( !bddPassed ){
echo 'There are regression suite failures.'
def mySubject = "Regression Test Failure: ${env.JOB_NAME} - Build# ${env.BUILD_NUMBER}"
def myBody = "Hi<br/>Please go to <a href='${env.BUILD_URL}Serenity'>the Serenity Report</a> to see more<br/>";
emailext attachLog: true,
mimeType: 'text/html',
body: myBody,
compressLog: true,
recipientProviders: [[$class: 'CulpritsRecipientProvider']],
subject: mySubject,
to: 'xxxxxxx'
}
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true,
keepAll: true, reportDir: 'regression/target/site/serenity', reportFiles: 'index.html',
reportName: 'Serenity', reportTitles: ''])
}
}
}