代码之家  ›  专栏  ›  技术社区  ›  Ceesiebird

Jenkins Pipeline Post Always步骤不在失败的构建上执行

  •  0
  • Ceesiebird  · 技术社区  · 7 年前

    我有一个Jenkins声明性管道,当构建状态成功时,它运行得很好。

    但是,当UI测试失败并且构建状态设置为“失败”时,总是忽略“发布”步骤中的所有代码。

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

    我不知道为什么詹金斯不运行后总是一步一步,以防失败的建设。

    我希望这篇文章总是在失败或成功的情况下运行,有人能向我解释为什么它不运行吗?

            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 */
                        }
                    }
            }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Ceesiebird    7 年前

    我添加了post,它总是直接跳到管道中测试步骤的末尾,而不是管道的绝对末端,现在它开始工作了。

    我认为这是Jenkins的管道机制中的一个错误,否则我希望post步骤永远不会运行,而不仅仅是在一个成功的场景中。