Jenkins: how to stop downstream projects when upstream is aborted

。_饼干妹妹 提交于 2020-01-06 08:38:37

问题


I have an upstream project in Jenkins which calls in sequence some downstream projects with the "Trigger/call builds on other projects" plugin.

How can I automatically abort a build of any downstream project when I perform the aborting of the upstream project?

If the upstream is aborted, the downstream is still running and I want a different behaviour.

Thanks.


回答1:


As mentioned in my comment, you can have downstream jobs listen to upstream jobs instead of having upstream jobs trigger downstream jobs. When it comes to parameters, the following groovy code example can be used to retrieve them:

def up_stream_cause = currentBuild.rawBuild.getCause(hudson.model.Cause$UpstreamCause)

if (up_stream_cause != null ) {
    def up_stream_run = up_stream_cause.upstreamRun
    def parameters_action = up_stream_run.getAction(ParametersAction)
    def parameters = parameters_action.getParameters()
}

Alternatively, you can of course simply build the downstream build during the upstream build using the following groovy code:

build job: 'job_name',
parameters: [
    [
        $class: 'StringParameterValue', name: 'parameter',
        value: 'value'
    ]
]

Both of those solutions allow you to not trigger a downstream build when your upstream build fails, aborts or is unstable.




回答2:


You can review:

https://wiki.jenkins.io/plugins/servlet/mobile?contentId=36603009#content/view/36603009

Pipeline jobs can by stopped by sending an HTTP POST request to URL endpoints of a build.

BUILD ID URL/stop - aborts a Pipeline.
BUILD ID URL/term - forcibly terminates a build (should only be used if stop does not work.
BUILD ID URL/kill - hard kill a pipeline. This is the most destructive way to stop a pipeline and should only be used as a last resort.

This last option is quite effective



来源:https://stackoverflow.com/questions/55399958/jenkins-how-to-stop-downstream-projects-when-upstream-is-aborted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!