Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-51865

Stage locks are created for skipped stages in declarative pipeline

      Given the following declarative pipeline:

      pipeline {
        stages {
          stage('Example stage') {
            when { expression { false } }
            options { lock resource: 'example resource' }
            steps { // ... }
          }
        }
      }
      

      Even though 'example stage' is skipped due to the when conditional, a lockable resource 'example resource' is created (if it doesn't already exist) and a lock is acquired on it. I think this is counter intuitive. The consequence is also really bad – a skipped stage might actually make the whole build hang (possibly for a long time) because it needs to acquire a lock on a busy resource (typically used by another build).

          [JENKINS-51865] Stage locks are created for skipped stages in declarative pipeline

          Thomas Johansen created issue -
          Thomas Johansen made changes -
          Description Original: Given the following declarative pipeline:
          {noformat}
          pipeline {
            stages {
              stage('Example stage') {
                when { expression { false } }
                options { lock resource: 'example resource' }
                steps { // ... }
              }
            }
          }
          {noformat}

          Even though 'example stage' is skipped due to the when conditional, a lockable resource 'example resource' is created (if it doesn't already exist) and a lock is acquired on it. I think this is counter intuitive -- one would not expect the lock to be acquired when the stage is skipped.
          New: Given the following declarative pipeline:
          {noformat}
          pipeline {
            stages {
              stage('Example stage') {
                when { expression { false } }
                options { lock resource: 'example resource' }
                steps { // ... }
              }
            }
          }
          {noformat}
          Even though 'example stage' is skipped due to the when conditional, a lockable resource 'example resource' is created (if it doesn't already exist) and a lock is acquired on it. I think this is counter intuitive. The consequence is also really bad – a skipped stage might actually make the whole build hang (possibly for a long time) because it needs to acquire a lock on a busy resource (typically used by another build).
          Andrew Bayer made changes -
          Component/s New: pipeline-model-definition-plugin [ 21706 ]
          Component/s Original: lockable-resources-plugin [ 18222 ]
          Assignee New: Andrew Bayer [ abayer ]
          Stephen Connolly made changes -
          Attachment New: Screenshot 2019-01-30 at 10.56.27.png [ 45838 ]
          D Pasto made changes -
          Link New: This issue is duplicated by JENKINS-55485 [ JENKINS-55485 ]
          Falko Modler made changes -
          Remote Link New: This issue links to "PR 356 (Web Link)" [ 23837 ]
          Falko Modler made changes -
          Assignee Original: Andrew Bayer [ abayer ] New: Falko Modler [ famod ]
          Falko Modler made changes -
          Released As New: https://github.com/jenkinsci/pipeline-model-definition-plugin/releases/tag/pipeline-model-definition-1.4.0
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Fixed but Unreleased [ 10203 ]
          Falko Modler made changes -
          Status Original: Fixed but Unreleased [ 10203 ] New: Resolved [ 5 ]
          Jesse Glick made changes -
          Link New: This issue causes JENKINS-61007 [ JENKINS-61007 ]

            famod Falko Modler
            thxmasj Thomas Johansen
            Votes:
            5 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: