0

I am not able to echo A or B or C when using condition in parallel block. I have used choice params for it.

It work when I am using global params but I want to use it in under one stage.

Pipeline:

pipeline {
    agent any
    parameters {
      choice choices: ['Dev', 'QA'], description: 'Make a choice', name: 'CLICK'
    }    
    stages {


      stage('Dev') {
        when { expression { params.CLICK == 'DEV' } }
        steps {
          echo "Dev"
        }
      }

      stage('QA') {
        when { expression { params.CLICK == 'QA' } }
        input {
            message "Choose appropriate Test?"
            parameters {
                choice choices: ['MobileAPP', 'FrontEnd', 'BankEnd'], description: 'Make a choice', name: 'CLICK1'
            }
        }  
        parallel {
            stage('A') {
                when {
                    expression { params.CLICK == 'MobileAPP' }
                }
                steps {
                  echo "A"
                } 
            }
            stage('B') {
                when {
                    expression { params.CLICK == 'FrontEnd' }
                }
                steps {
                  echo "B"
                } 
            }
            stage('C') {
                when {
                    expression { params.CLICK == 'BackEnd' }
                }
                steps {
                  echo "C"
                } 
            }
        }
      }
    }
}

Wrong output:

enter image description here

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Mayank C Koli
  • 21
  • 1
  • 3

1 Answers1

0

Well, I could acheive it by make stage level paramters as global and then use them in another stages which worked as expected.

  stage('QA') {
    when { expression { params.CLICK == 'QA' } }
      steps {
        script {
           CHOICES = ['MobileAPP', 'FrontEnd', 'BankEnd'];    
                    env.CLICK1 = input  message: 'Choose appropriate Test?',ok : 'Deploy',id :'tag_id', parameters:[choice(choices: CHOICES, description: 'Make a choice', name: 'Select')]
                } 

            }
    }  
    parallel {
        stage('A') {
            when {
                expression { env.CLICK == 'MobileAPP' }
            }
            steps {
              echo "A"
            } 
        }
        stage('B') {
            when {
                expression { env.CLICK == 'FrontEnd' }
            }
            steps {
              echo "B"
            } 
        }
        stage('C') {
            when {
                expression { env.CLICK == 'BackEnd' }
            }
            steps {
              echo "C"
            } 
        }
    }
  }
}
Mayank C Koli
  • 21
  • 1
  • 3