Issue
properties([gitLabConnection(gitLabConnection: 'GitLab Connection', jobCredentialId: ''), [$class: 'GitlabLogoProperty', repositoryName: ''], parameters([extendedChoice(multiSelectDelimiter: ',', name: 'choice', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_CHECKBOX', value: 'mongo, mysql', visibleItemCount: 10)])])
pipeline { agent anyenter image description here
stages {
stage('mongo') {
when {
expression { choice == 'mongo' }
}
steps {
echo "${params.choice}"
}
}
stage('mysql') {
when {
expression { choice == 'mysql' }
}
steps {[enter image description here][1]
echo "${params.choice}"
}
}
}
}
Solution
I couldn't get the extendedChoice Parameters setup in the declarative pipeline. Instead, I used Boolean Parameters. Please refer to the following for your use case. Note I have declared a global variable named choice.
def choice = ""
pipeline {
agent any
stages {
stage("Get details") {
steps{
timeout(time: 300, unit: 'SECONDS') {
script {
// Select the product image
choice = input message: 'Please select the product', ok: 'Build',
parameters: [
booleanParam(defaultValue: false, name: 'mongo'),
booleanParam(defaultValue: false, name: 'mysql')]
}
}
}
}
stage('Echo') {
steps {
script {
echo "::: Product : ${choice}"
}
}
}
stage('mongo') {
when {
expression { return choice.get("mongo") }
}
steps {
echo "MONGO"
}
}
stage('mysql') {
when {
expression { return choice.get("mysql") }
}
steps {
echo "MYSQL"
}
}
}
post {
success {
echo 'The process is successfully Completed....'
}
}
}
Answered By - ycr
Answer Checked By - Katrina (JavaFixing Volunteer)