-
Bug
-
Resolution: Duplicate
-
Major
-
None
-
Jenkins ver. 2.46.1 (LTS)
Pipeline: API / Model 1.1.2
All other plugins are currently up to date too.
OS: Windows 7
I am extracting the contents of my Jenkinsfile to a common library to reuse it in a number of projects. I have a build step that may be deactivated related on some user input and this is done via when
This works fine when using the Jenkinsfile but does not as soon as i put it in a library
Jenkinsfile
@Library('mybuild') _ buildPipeline { name = 'shared build pipeline' }
this is the content of the sharedLibrary:
var/buildPipeline.groovy
def call(Closure body) { // evaluate the body block, and collect configuration into the object def config = [:] body.resolveStrategy = Closure.DELEGATE_FIRST body.delegate = config body() // here starts the "real" pipeline pipeline { agent any stages { stage("Two") { when { expression { echo "Should I run?" return false } } steps { echo "World" echo "Heal it" } } } // stages } // pipeline }
expected is:
[Pipeline] stage [Pipeline] { (Two) Stage 'Two' skipped due to when conditional [Pipeline] echo 15:36:18 Should I run? [Pipeline] } [Pipeline] // stage
but i get
[Pipeline] stage [Pipeline] { (Two) [Pipeline] echo World [Pipeline] echo Heal it [Pipeline] } [Pipeline] // stage
anything i am missing?
- duplicates
-
JENKINS-42224 Need ability to create reusable chunks of Declarative Pipeline
- Open