如果下游作业失败,则将上游Jenkins / Hudson标记为失败

时间:2011-06-19 17:02:48

标签: continuous-integration hudson jenkins hudson-plugins

我使用Parameterized Trigger Plugin来触发下游构建。

如果下游失败,如何指定上游作业失败?上游作业实际上是虚拟作业,参数传递给下游。

4 个答案:

答案 0 :(得分:17)

确保使用正确的步骤执行下游作业;我发现自从我执行我的“后构建步骤”以来,我没有“阻止直到被触发的项目完成他们的构建”选项。将其更改为“构建任务”而不是“构建后任务”,允许我在参数化触发器插件中找到您要查找的选项。

enter image description here

答案 1 :(得分:5)

此代码将根据下游作业状态标记上游构建不稳定/失败。

/*************************************************
Description: This script needs to put in Groovy 
Postbuild plugin of Jenkins as a Post Build task.
*************************************************/

import hudson.model.*

void log(msg) {
  manager.listener.logger.println(msg)
}

def failRecursivelyUsingCauses(cause) {
     if (cause.class.toString().contains("UpstreamCause")) {
        def projectName = cause.upstreamProject
        def number = cause.upstreamBuild
        upstreamJob = hudson.model.Hudson.instance.getItem(projectName)
        if(upstreamJob) {
             upbuild = upstreamJob.getBuildByNumber(number)
             if(upbuild) {
                 log("Setting to '" + manager.build.result + "' for Project: " + projectName + " | Build # " + number)
                 //upbuild.setResult(hudson.model.Result.UNSTABLE)
                 upbuild.setResult(manager.build.result);
                 upbuild.save()

                 // fail other builds
                 for (upCause in cause.upstreamCauses) {
                     failRecursivelyUsingCauses(upCause)
                 }
             }
        } else {
            log("No Upstream job found for " + projectName);
        }
    }
}


if(manager.build.result.isWorseOrEqualTo(hudson.model.Result.UNSTABLE)) {
    log("****************************************");
    log("Must mark upstream builds fail/unstable");
    def thr = Thread.currentThread()
    def build = thr.executable
    def c = build.getAction(CauseAction.class).getCauses()

    log("Current Build Status: " + manager.build.result);
    for (cause in c) {
        failRecursivelyUsingCauses(cause)
    }
    log("****************************************");
}
else {
    log("Current build status is: Success - Not changing Upstream build status");
}

答案 2 :(得分:1)

查看以下回复:Fail hudson build with groovy script。您可以访问上游作业并使其构建失败但是......请注意Hudson / Jenkins现在的后构建操作不允许指定任何排序这一事实:如果除了其他后期构建之外还指定了groovy脚本如果Jenkins决定在你的groovy脚本之后运行它们,那么你将无法更新上游作业的状态。

答案 3 :(得分:0)

在“构建”步骤下,在其他项目上配置“触发/调用”构建,选择下游作业。选择“阻止,直到触发的项目完成其构建”。在其下保存默认设置。此设置将使上游作业失败,而下游作业失败。