【问题标题】:Run Cleanup Phase when a test phase job fails当测试阶段作业失败时运行清理阶段
【发布时间】:2019-03-11 05:59:03
【问题描述】:

我在 Jenkins Multijob 项目中有 2 个阶段。一个清理阶段和其他阶段有 4 个测试作业按顺序运行。

我的问题是当 4 个测试作业之一失败时,我想运行清理阶段,然后重新运行失败的作业。

这可以在 Jenkins 上完成吗?

【问题讨论】:

  • 请考虑使用“并行”步骤切换到 Jenkins 流水线(MultiJob 尚不支持流水线并且可能不会支持它)。如果您仍然希望在 MultiJob 中使用此功能,请在 github.com/jenkinsci/tikal-multijob-plugin/issues 中为它打开一个问题

标签: jenkins jenkins-plugins jenkins-pipeline build-automation ready-api


【解决方案1】:

是的,您可以使用 jenkins 管道实现您想要的。我在下面提供了 3 个测试作业的示例:

node{
    def results = new String[3]
    stage("Run tests"){
        for(int i=1; i<=3; i++) {
            // Run tests and store results (SUCCESS, FAILURE, etc.) in array
            results[i-1] = build(job: "TEST_JOB_$i", propagate: false).result
        }
        // If at least one test failed
        if("FAILURE" in results)
        {
            build job: 'CLEANUP_JOB', propagate: false
            for(int i=1; i<=3; i++) {
                if(results[i-1] == "FAILURE")
                {
                    // If this job fails now, then current build ends with failure
                    build(job: "TEST_JOB_$i", propagate: true)   
                }
            }
        }
    }
}

"propagate: false" 会导致管道的其余部分运行,即使构建失败也是如此。用Multijob插件可以实现类似的东西,但是会很丑。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-22
    • 1970-01-01
    • 1970-01-01
    • 2019-09-24
    • 1970-01-01
    • 2019-08-29
    • 1970-01-01
    • 2017-07-27
    相关资源
    最近更新 更多