Jenkins:运行 Serenity 验收测试没有失败

Jenkins: Run Serenity acceptance tests without failure

我正在努力实现以下目标:

  1. 运行 一组 Serenity(加上 Cucumber)测试作为构建管道的一部分
  2. 无论所有测试是否通过都收集报告(显然它们在失败时特别有用)
  3. 仅在测试失败的情况下,然后向贡献者发送电子邮件
  4. 永远不会因为验收测试失败而导致构建失败,因为此管道用于提交 CI。仅当 Nightly 中的验收测试失败时才希望失败。

考虑到所有这些,我开始尝试配置构建:

    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 参数?

非常感谢任何帮助。

我认为你需要在 shell 周围放置一个 try/catch(所以 运行 它在 script{} 块中),并在 catch 中发送你的电子邮件.然后您可以将构建设置为 SUCCESS。

我实际上以与@Rob 的建议略有不同的方式解决了这个问题,但关键是理解我想做的事情需要使用带有 returnStatus 标志的 script 块.我更喜欢这个而不是 try-catch,因为我实际上(不幸的是)期望它不时失败,所以更愿意在下面分支。

  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: ''])
          }
       }  
    }