-
Bug
-
Resolution: Fixed
-
Critical
-
None
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).
- causes
-
JENKINS-61007 pipeline-model-definition is using findbugs without providing / depending on it
-
- Resolved
-
- is duplicated by
-
JENKINS-55485 Declarative pipeline, lock() in stage options is executed before when clause
-
- Closed
-
- links to
Ok, got it. So this is a feature request. I was really happy when the 'beforeAgent' option was introduced to the when block. Guess I'm looking for a 'beforeLock' option too, then.
The lock is released as it should. The problem (or rather my problem) is that the lock is required at all. My current workaround is to rename the lock resource when the stage should be skipped, but it makes the code a little messy.