Aborting pipeline from a plugin

25 views
Skip to first unread message

zbyne...@gmail.com

unread,
Mar 22, 2024, 5:11:23 PM3/22/24
to Jenkins Developers
Hi,

I've been trying to fix a bug in the scmSkip plugin where pipeline job is marked as aborted, but does not actually stop. I found 4 ways to stop a WorkflowRun
* calling interrupt on either executor (getExecutor or getOneOffExecutor) -- effectively what the plugin does right now, it does not stop the pipeline though
* calling doKill -- kills the job *too* well, even the "post {always}" part is skipped
* throwing AbortException -- stops the job and executes "post {always}", but job is FAILED rather than ABORTED

The following pipeline illustrates the problem:

pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                script {
                echo "this should be printed"
                // calling interrupt directly, should be done by plugin
                currentBuild.rawBuild.getOneOffExecutor().interrupt(Result.ABORTED)
                currentBuild.rawBuild.getExecutor().interrupt(Result.ABORTED)
                echo "this should be skipped"
                }
            }
        }
    }
   
    post {
        always {
            echo "this should be printed again"
        }
    }
}

Somehow "this should be skipped" is always printed (at least in environment with SSH agents).

What is the correct way to abort pipeline programmatically?

Thanks,
Zbynek

Basil Crow

unread,
Mar 23, 2024, 3:41:13 AM3/23/24
to jenkin...@googlegroups.com
On Fri, Mar 22, 2024 at 2:11 PM zbyne...@gmail.com <zbyne...@gmail.com> wrote:
> What is the correct way to abort pipeline programmatically?

See https://javadoc.jenkins.io/plugin/workflow-step-api/org/jenkinsci/plugins/workflow/steps/FlowInterruptedException.html.

Zbynek Konecny

unread,
Mar 25, 2024, 3:36:41 AM3/25/24
to jenkin...@googlegroups.com
Thanks, that works!

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAFwNDjrwoE1jsSQgZ4OVQHhDPXE5EsfrSQNHdNEJ3aD13WDDuw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages