【问题标题】:Jenkins pipeline post always step doesn't execute on failing buildJenkins管道发布总是在构建失败时不执行步骤
【发布时间】:2019-05-01 16:08:50
【问题描述】:

我有一个 Jenkins 声明式管道,它在构建状态成功时运行良好。

但是,当 UI 测试失败并且构建状态设置为失败时,post 步骤中的所有代码都会被忽略。

我已经检查过是否可能在测试失败的情况下未创建测试报告,但这些报告存在于指定位置。

我不知道为什么 Jenkins 不会在构建失败的情况下始终运行帖子。

我希望帖子总是在失败或成功的情况下运行,谁能向我解释为什么它不运行?

        post {
        always {
                node('master') {
                    dir('/appl/jenkins/test/workspace/pipeline/test-reports') {
                        unstash 'test-report'

                        // This plugin script replaces the hard coded D:\ drive references with the path of the Jenkins job
                        // in order to make screenshot links function OK in the Jenkins copy of the HTML report.

                        //TODO add build number to report to identify test run.
                        echo 'Run completed before script block'

                        script {
                            contentReplace(
                                    configs: [
                                            fileContentReplaceConfig(
                                                    configs: [
                                                            fileContentReplaceItemConfig(
                                                                    search: 'original_path',
                                                                    replace: 'replaced_path',
                                                                    matchCount: 0)
                                                    ],
                                                    fileEncoding: 'UTF-8',
                                                    filePath: '/appl/jenkins/test/workspace/pipeline/test-reports/report.html')
                                    ])
                        }

                        echo 'Run completed after script block'

                        // Below we use the Publish HTML plugin to publish the report.html resulting from the Extend Reports plugin.
                        publishHTML target: [
                                allowMissing         : false,
                                alwaysLinkToLastBuild: false,
                                keepAll              : true,
                                reportDir            : '/appl/jenkins/test/workspace/pipeline/test-reports',
                                reportFiles          : 'report.html, *.png',
                                reportName           : 'Extent Report deluxe (screenshots!)'
                        ]

                        echo 'Run completed after publish block'

                        //deleteDir() /* clean up Master workspace */
                    }
                }
        }

【问题讨论】:

  • 这是scripted pipeline 还是Declarative 管道
  • 嗨 Gaurang,这是关于声明性管道的。
  • 你能在node('master') 之前尝试echo "always",看看你是否在日志中收到这条消息。

标签: jenkins jenkins-pipeline


【解决方案1】:

我已将帖子始终直接添加到管道中测试步骤的末尾,而不是管道的绝对末尾,现在它可以工作了。

我认为这是 Jenkins 流水线机制中的一个错误,否则我希望 post 步骤永远不会运行,而不仅仅是在成功的情况下运行。

【讨论】:

    【解决方案2】:

    确保在构建时“传播”未设置为 true,如果是则将其更改为传播:false

    【讨论】:

      猜你喜欢
      • 2022-01-17
      • 2019-07-08
      • 1970-01-01
      • 1970-01-01
      • 2017-10-09
      • 2012-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多