Skip to content

Instantly share code, notes, and snippets.

@thomaschaplin
Last active August 24, 2022 13:58
Show Gist options
  • Select an option

  • Save thomaschaplin/ae18b1730d929d42b6039f222ca69a28 to your computer and use it in GitHub Desktop.

Select an option

Save thomaschaplin/ae18b1730d929d42b6039f222ca69a28 to your computer and use it in GitHub Desktop.
How to kill a Jenkins job via the script console

How to kill a Jenkins job via the Script Console

Steps

Step 1

Find the name of the job, this is usually in the URL - https://jenkins.domain.io/job/job-name-example/123 In this example URL the job name would be - job-name-example

Step 2

Find the number of the job, this is usually in the URL - https://jenkins.domain.io/job/job-name-example/123 In this example URL the job number would be - 123

Step 3

Navigate to the Script Console in Jenkins UI - https://jenkins.domain.io/script

Step 4

Paste the following code block into the console and replace the JOB_NAME and JOB_NUMBER for the values you found in step 2 and 3.

Jenkins.instance.getItemByFullName("JOB_NAME").getBuildByNumber(JOB_NUMBER).finish(hudson.model.Result.ABORTED, new java.io.IOException("Manually aborting job via Script Console"));

Step 5

Click Run

Step 6

Check the job has been aborted by going back to the original job url - https://jenkins.domain.io/job/job-name-example/123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment