0
votes

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.

2
Can't you just have downstream jobs listen to upstream jobs instead of having upstream jobs trigger downstream jobs? Job configuration of downstream build > Build triggers > Build after other projects are builtRemy
I can't because the upstream project needs parameters that have to be used as input for downstream projects.Alessandro C

2 Answers

0
votes

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.

0
votes

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