【问题标题】:Jenkins: Run Serenity acceptance tests without failureJenkins:运行 Serenity 验收测试而不会失败
【发布时间】:2017-10-22 23:18:43
【问题描述】:

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

  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 发送到mvncommand,但这意味着我无法通过电子邮件发送有关损坏的回归测试的信息。

所以我想知道是否有其他人以某种聪明的方式处理过这个问题。我是否需要分配退出代码或其他内容,这是否涉及覆盖 Jenkins 中的默认 shell 参数?

非常感谢任何帮助。

【问题讨论】:

    标签: maven jenkins jenkins-pipeline serenity-bdd


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我实际上以与@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: ''])
                }
             }  
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-02-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-17
        • 2011-09-16
        • 2015-11-18
        • 1970-01-01
        相关资源
        最近更新 更多