Issue
I am trying to convert Scripted pipelines into Declarative Pipeline.
Here is a Pipeline:
pipeline {
agent any
parameters {
string(defaultValue: '',
description: '',
name : 'BRANCH_NAME')
choice (
choices: 'DEBUG\nRELEASE\nTEST',
description: '',
name : 'BUILD_TYPE')
}
stages {
stage('Release build') {
when {
expression {params.BRANCH_NAME == "master"}
expression {params.BUILD_TYPE == 'RELEASE'}
}
steps {
echo "Executing Release\n"
}
} //stage
} //stages
} // pipeline
Intension is that all the parameter values need to be compared under when
and only then I wanted executed a stage.
In scripted pipeline you can use && like in snippet below.
stage('Release build') {
if ((responses.BRANCH_NAME == 'master') &&
(responses.BUILD_TYPE == 'RELEASE')) {
echo "Executing Release\n"
}
}
How to get collective return from expression
in declarative pipeline?
Solution
It has to be like
pipeline {
agent any
parameters {
string(defaultValue: '',
description: '',
name : 'BRANCH_NAME')
choice (
choices: 'DEBUG\nRELEASE\nTEST',
description: '',
name : 'BUILD_TYPE')
}
stages {
stage('Release build') {
when {
allOf {
expression {params.BRANCH_NAME == "master"};
expression {params.BUILD_TYPE == 'RELEASE'}
}
}
steps {
echo "Executing Release\n"
}
} //stage
} //stages
} // pipeline
you can find other dsl support inside when
here
Answered By - Samit Kumar Patel