49

I am using pipeline jobs with Jenkins 2.0, but I don't see option 'disable job' as I was used to in older Jenkins versions. Am I missing something? Is it still possible to disable (pipeline) job?

miran
  • 1,419
  • 1
  • 12
  • 26
  • As far as I know based on looking through the source code, there is no disable function support. But hopefully get confirmed from some other people. – Tim Aug 05 '16 at 10:37

8 Answers8

40

You can simply use the "Disable Project" option from Jenkins 2.89.4 onward in order to disable the pipeline Jobs.

Rashi sharma
  • 424
  • 5
  • 2
26
  • go to job configuration
  • under "Build Triggers" select the "Disable this project"
  • save

enter image description here

Maoz Zadok
  • 4,871
  • 3
  • 33
  • 43
21

If you don't find the disable button. This should do the trick for most of the Jobs. Just append /disable to the end of Job URL. Then Jenkins will redirect you to a page where you can Post. Same applies for /enable too

enter image description here

so-random-dude
  • 15,277
  • 10
  • 68
  • 113
  • 1
    Note that any config change toggles the flag, so you have to keep disabling it with this workaround. – MarkHu Sep 17 '19 at 17:03
  • I found out that I'm missing the needed permission this way. Weird that Jenkins just hides the "enable/disable" button in that case... – Lerk May 27 '20 at 09:56
  • FYI - no indicator of disabled status on the job. Though you can tell if you make note that the job's icon changes from the pipeline symbol to a dim folder. – Bill Tarbell Feb 03 '23 at 15:10
19

There is no option to disable jenkins-pipeline job.

The following jira ticket is tracking the issue:

https://issues.jenkins-ci.org/browse/JENKINS-27299

Fahd Arshad
  • 191
  • 1
  • 3
  • 7
    Disable option was added in Pipeline Job v.2.11 on May 12, 2017 – ALex_hha May 29 '17 at 13:54
  • 1
    @ALex_hha but *how* is the option used? – Mark Stosberg Aug 04 '17 at 20:18
  • Even though you can't disable the actual job, what you can do for a multi-branch pipeline is to add a filter for the branch names that excludes all branches (with a wildcard). – Joan Rieu Jan 08 '18 at 13:23
  • 3
    @JoanRieu This immediately and completely wipes out the build history for that job; even if you undo the filter the first build starts back at 1 – Michael Mrozek Apr 17 '18 at 17:28
  • 2
    Follow-up to my previous comment: you can prevent this by marking at least one build in each branch "keep forever". This causes the branch to be disabled instead of removed – Michael Mrozek Jun 05 '18 at 17:38
15

For multibranch pipeline projects,

  • Click on pipeline 'configuration'
  • Under the 'Branch Sources', below 'Property Strategy'
    • click on 'ADD PROPERTY'
    • select "Suppress automatic SCM triggering"

Now, no github branch trigger will run a build job. (This will disable triggers for all branches)

Harshit
  • 617
  • 1
  • 6
  • 15
0

I have a similar case and found that a lot of our jobs are/were set up by an automatic "seeder" job that created them from Job DSL, and their configurations aren't editable. So i went to GitHub and disabled the webhook connecting the two. So the job is still active, but should never be triggered by GitHub activity anymore.

Max Cascone
  • 648
  • 9
  • 25
0

If, like me, your Jenkins jobs are automatically created by a DSL workflow, you won't be able to edit the configuration of the top-level Job, that contains all the actual branches, to disable the automatic builds from github hooks. I can't currently find a way to programmatically disable an entire pipeline in the jenkinsfile, outside of using the when triggered by clause on every stage as mentioned in this other SO answer. Besides, that would cause it to run and succeed, which might not be what we want.

So the solution that felt least-hacky to me was:

  1. Change the name of the Jenkinsfiles on all branches in your repo to something other than Jenkinsfile, so that Jenkins' SCM polling doesn't pick it up. I chose Jenkinsfile.manual. This assumes that the job-auto-creator is set to look for "Jenkinsfile"; adjust as necessary.
  2. The auto-created job should delete itself the next time it scans the repo, whether that's from the github hook, a scheduled scan, or you pressing "scan now".
  3. Manually create a new Multibranch Pipeline job for your repo, setting the Build Configuration to look for Jenkinsfile.manual (or whatever you choose to call it).
  4. Configure whatever branch Behaviors you would normally use, but also add a Property Strategy of All branches get the same properties > Suppress automatic SCM triggering.

This feels "right" to me, your mileage my vary.

Max Cascone
  • 648
  • 9
  • 25
0

I excluded all branches (Exclude: *) in my Branch Sources -> GitHub -> Behaviors -> Filter by name (with wildcards) -> Exclude section

Jenkins screenshot: Branch Sources -> GitHub -> Behaviors -> Filter by name (with wildcards) -> Exclude: *

Heath Borders
  • 30,998
  • 16
  • 147
  • 256