-
Story
-
Resolution: Duplicate
-
Major
-
None
-
Jenkins ver. 2.60.1
There are multiple projects with similar pipelines.
I can reuse declarative pipeline right now by importing library with pipeline defined:
Jenkinsfile:
@Library('github.com/my/libs@master') _ common_jenkinsfile { // project parameters }
github.com/my/libs/common_jenkinsfile.groovy:
def call(body) { def config = [:] body.resolveStrategy = Closure.DELEGATE_FIRST body.delegate = config body() pipeline { agent any stages { stage('This one should be skipped') { when { expression { false } } steps { echo "this should be skipped, but it does not (" } } } } }
The problems are:
- This is not officially supported, so can break with any next Jenkins release
- 'when' does not work in this case, so stages are never skipped
- duplicates
-
JENKINS-42224 Need ability to create reusable chunks of Declarative Pipeline
-
- Open
-
- is related to
-
JENKINS-42224 Need ability to create reusable chunks of Declarative Pipeline
-
- Open
-
[JENKINS-45306] Sharing of declarative pipeline between similar projects
Description |
Original:
Stage with dedicated agent in this pipeline is not skipped: \{\{ pipeline \{ agent none stages \{ stage('This one is not skipped :(') \{ when \{ expression \{ false } } agent any steps \{ echo "this should be skipped, but it won't" } } } } }} Log: [Pipeline] stage [Pipeline] \{ (This one is not skipped :() [Pipeline] node Running on iOS-xc in /Users/jenkins/slave/workspace/Pipeline_when [Pipeline] \{ Stage 'This one is not skipped :(' skipped due to when conditional [Pipeline] } [Pipeline] // node [Pipeline] } [Pipeline] // stage [Pipeline] End of Pipeline Simple pipeline with single agent works fine: \{\{ pipeline \{ agent none stages \{ stage('This one is not skipped :(') \{ when \{ expression \{ false } } agent any steps \{ echo "this should be skipped, but it won't" } } } } }} Log: [Pipeline] node Running on iOS-xc in /Users/jenkins/slave/workspace/Pipeline_when [Pipeline] \{ [Pipeline] stage [Pipeline] \{ (This on is skipped) Stage 'This on is skipped' skipped due to when conditional [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline |
New:
Stage with dedicated agent in this pipeline is not skipped ('when' does not work): {code:java} pipeline { agent none stages { stage('This one is not skipped :(') { when { expression { false } } agent any steps { echo "this should be skipped, but it won't" } } } } {code} Log: {panel} [Pipeline] stage [Pipeline] \{ (This one is not skipped :() [Pipeline] node Running on iOS-xc in /Users/jenkins/slave/workspace/Pipeline_when [Pipeline] \{ Stage 'This one is not skipped :(' skipped due to when conditional [Pipeline] } [Pipeline] // node [Pipeline] } [Pipeline] // stage [Pipeline] End of Pipeline {panel} Simple pipeline with single agent works fine: {code:java} pipeline { agent any stages { stage('This on is skipped') { when { expression { false } } steps { echo "this should be skipped and it will" } } } } {code} Log: {panel} [Pipeline] node Running on iOS-xc in /Users/jenkins/slave/workspace/Pipeline_when [Pipeline] \{ [Pipeline] stage [Pipeline] \{ (This on is skipped) Stage 'This on is skipped' skipped due to when conditional [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline {panel} |
Resolution | New: Not A Defect [ 7 ] | |
Status | Original: Open [ 1 ] | New: Closed [ 6 ] |
Summary | Original: 'when' does not skip stage with dedicated agent | New: Sharing of declarative pipeline between similar projects |
Description |
Original:
Stage with dedicated agent in this pipeline is not skipped ('when' does not work): {code:java} pipeline { agent none stages { stage('This one is not skipped :(') { when { expression { false } } agent any steps { echo "this should be skipped, but it won't" } } } } {code} Log: {panel} [Pipeline] stage [Pipeline] \{ (This one is not skipped :() [Pipeline] node Running on iOS-xc in /Users/jenkins/slave/workspace/Pipeline_when [Pipeline] \{ Stage 'This one is not skipped :(' skipped due to when conditional [Pipeline] } [Pipeline] // node [Pipeline] } [Pipeline] // stage [Pipeline] End of Pipeline {panel} Simple pipeline with single agent works fine: {code:java} pipeline { agent any stages { stage('This on is skipped') { when { expression { false } } steps { echo "this should be skipped and it will" } } } } {code} Log: {panel} [Pipeline] node Running on iOS-xc in /Users/jenkins/slave/workspace/Pipeline_when [Pipeline] \{ [Pipeline] stage [Pipeline] \{ (This on is skipped) Stage 'This on is skipped' skipped due to when conditional [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline {panel} |
New:
There are multiple projects with similar pipelines. I can reuse declarative pipeline right now by importing library with pipeline defined: Jenkinsfile: {code:java} @Library('github.com/my/libs@master') _ common_jenkinsfile { // project parameters } {code} github.com/my/libs/common_jenkinsfile.groovy: {code:java} def call(body) { def config = [:] body.resolveStrategy = Closure.DELEGATE_FIRST body.delegate = config body() pipeline { agent any stages { stage('This one should be skipped') { when { expression { false } } steps { echo "this should be skipped, but it does not (" } } } } } {code} The problems are: - This is not officially supported, so can break with any next Jenkins release - 'when' does not work in this case, so stages are never skipped |
Resolution | Original: Not A Defect [ 7 ] | |
Status | Original: Closed [ 6 ] | New: Reopened [ 4 ] |
Component/s | New: pipeline-model-definition-plugin [ 21706 ] | |
Issue Type | Original: Bug [ 1 ] | New: Story [ 10002 ] |
Priority | Original: Minor [ 4 ] | New: Major [ 3 ] |
Link | New: This issue is related to JENKINS-42224 [ JENKINS-42224 ] |
Link | New: This issue duplicates JENKINS-42224 [ JENKINS-42224 ] |
Resolution | New: Duplicate [ 3 ] | |
Status | Original: Reopened [ 4 ] | New: Resolved [ 5 ] |