[英]Marking upstream Jenkins/Hudson as failed if downstream job fails
I am using Parameterized Trigger Plugin to trigger a downstream build. 我使用参数化触发插件来触发下游构建。
How do I specify that my upstream job should fail if the downstream fails? 如果下游失败,如何指定我的上游作业应该失败? The upstream job is actually is dummy job with parameters being passed to the downstream.
上游作业实际上是虚拟作业,参数传递给下游。
Make sure you are using the correct step to execute your downstream jobs; 确保使用正确的步骤执行下游作业; I discovered that since I was executing mine as a "post build step", I didn't have the "Block until the triggered projects finish their builds" option.
我发现自从我执行我的“后构建步骤”以来,我没有“阻止直到被触发的项目完成他们的构建”选项。 Changing that to "build task" as opposed to a "post build task", allowed me to find the options you are looking for within the Parameterized Trigger Plugin.
将其更改为“构建任务”而不是“后构建任务”,允许我在参数化触发器插件中找到您要查找的选项。
this code will mark the upstream build unstable/failed based on downstream job status. 此代码将根据下游作业状态标记上游构建不稳定/失败。
/*************************************************
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");
}
Have a look at the following response: Fail hudson build with groovy script . 看看下面的响应: 使用groovy脚本构建失败的hudson 。 You can get access to the upstream job and fail its build BUT... be careful with the fact that Hudson/Jenkins post-build actions right now do not allow to specify any ordering: if your groovy script is specified besides other post-build actions, and those actions affect the result of the build (ie: parsing of test results), then you won't be able to update the status of the upstream job if Jenkins decides to run them after your groovy script.
您可以访问上游作业并使其构建失败但是......请注意Hudson / Jenkins现在的后构建操作不允许指定任何排序这一事实:如果除了其他后期构建之外还指定了groovy脚本动作,这些动作会影响构建的结果(即:解析测试结果),如果Jenkins决定在你的groovy脚本之后运行它们,你将无法更新上游作业的状态。
Under Build step configure Trigger/Call builds on other projects, choose the downstream job. 在Build步骤下,在其他项目上配置Trigger / Call构建,选择下游作业。 Select "Block until triggered project finish their build".
选择“阻止直到触发的项目完成其构建”。 Save the default settings under it.
保存其下的默认设置。 This settings will make upstream job failed is downstream is failed.
此设置将使上游作业失败,下游失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.