lockable-resources-plugin icon indicating copy to clipboard operation
lockable-resources-plugin copied to clipboard

Unclear about declarative pipeline

Open Sunderfield opened this issue 7 years ago • 2 comments

I am trying to rewrite my pipeline script for maintainablity but am unclear how to lock the resource for the entire script, is it possible to do something like:

pipeline {
    agent any 
    resource: ('lockable resource')

    stages {
        stage('Build') { 
            steps { 
                sh 'make' 
            }
        }
        stage('Test'){
            steps {
                sh 'make check'
                junit 'reports/**/*.xml' 
            }
        }
        stage('Deploy') {
            steps {
                sh 'make publish'
            }
        }
    }
}

Sunderfield avatar May 21 '17 11:05 Sunderfield

I have a similar problem. This would be a great feature. Also, take a look on JENKINS-43336. This could be resolved with the same solution. PS. You can vote for issue ;)

mateusz-was avatar May 22 '17 14:05 mateusz-was

You can lock the entire job in the options block of the pipeline:

 pipeline {
options {
      lock resource: 'lockable resource'
    }
   

 agent any 
 
    stages {
        stage('Build') { 
            steps { 
                sh 'make' 
            }
        }
        stage('Test'){
            steps {
                sh 'make check'
                junit 'reports/**/*.xml' 
            }
        }
        stage('Deploy') {
            steps {
                sh 'make publish'
            }
        }
    }
}

wheatgrinder avatar Jun 19 '19 16:06 wheatgrinder