jpereira
jpereira

Reputation: 251

Allow same Jenkins job to be launched only after a certain step in the pipeline

I currently have a Jenkins Pipeline job that have multiple steps, and I only want a new run of this pipeline to be allow to start when the previous pipeline reach a certain point.

Ex: My pipeline as the following stages: A -> B -> C -> D -> E

If I start twice this pipeline I would like the second Run to be only launched when the first one reaches stage C.

Thanks

Update:

This pipeline is being launched by a Git trigger, so I want to make sure that 2 push into the repo will be handled.

Ex:

Developer A push a commit and Pipeline starts

Developer B push a commit but Pipeline from DevA still running so I want this to wait

When DevA Pipeline reaches the stage C I want to allow the Pipeline from DevB to start

Upvotes: 0

Views: 382

Answers (3)

amuniz
amuniz

Reputation: 3342

You can use the lock step (included as part of lockable-resources-plugin.

Your script would look like this:

lock('my-resource') {
  stage('A') {...}
  stage('B') {...}
  stage('C') {...}
}
stage('D')
stage('E')

Upvotes: 2

Krzysztof Krasoń
Krzysztof Krasoń

Reputation: 27516

I think that the most "official" way is to use lockable resources plugin.(implemented as part of https://issues.jenkins-ci.org/browse/JENKINS-30269)

Upvotes: 0

arved
arved

Reputation: 4594

You might use the "Throttle Concurrent Builds Plugin" https://wiki.jenkins-ci.org/display/JENKINS/Throttle+Concurrent+Builds+Plugin

Put A,B and C in one group and allow only one build job for this group

Upvotes: 0

Related Questions