How to lock multiple stages of declarative Jenkins pipeline?

前端 未结 5 868
孤独总比滥情好
孤独总比滥情好 2020-12-23 19:30

I want to run multiple stages inside a lock within a declarative Jenkins pipeline:

pipeline {
    agent any
    stages {
        lock(resource: \'myResource\         


        
5条回答
  •  自闭症患者
    2020-12-23 20:20

    If the resource is only used by this pipeline you could also disable concurrent builds:

    pipeline {
        agent any
        options {
            disableConcurrentBuilds()
        }
        stages {
            stage('will_already_be_locked') {
                steps {
                    echo "I am locked before I enter the stage!"
                }
            }
            stage('will_also_be_locked') {
                steps {
                    echo "I am still locked!"
                }
            }
       }
    }
    

提交回复
热议问题