Russell
Russell

Reputation: 1432

Check if a downstream job is enabled before triggering it

I have a job (JobA) which, upon success, builds JobB. The Jenkinsfile for JobA contains a post section like this:

post {
  success {
    build job: 'JobB', wait: false
  }
}

The problem is that when JobB is disabled, JobA will fail no matter what with the following message:

ERROR: Failed to trigger build of JobB
Finished: FAILURE

Can I prevent JobA from failing when JobB is disabled while still using declarative syntax?

Upvotes: 2

Views: 1750

Answers (1)

bigbaeng
bigbaeng

Reputation: 75

Before triggering the post job, you can first check if JobB is enabled/disabled via isBuildable().

Jenkins.instance.getItem("JobB").isBuildable()

Upvotes: 2

Related Questions