Disable a Jenkins job from within Pipeline Groovy

Posted on October 26th, 2018 at 18:00 PM


Disable a Jenkins job from within a Pipeline job using Groovy with the following:

def job = Jenkins.instance.getItem(targetJob)
job.setDisabled(true)

The target job can be Pipeline or Freestyle. Setting to false will enable the target job again.