Search code examples
jenkinsjenkins-workflowjenkins-pipeline

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


Solution

  • 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')