并行级声明管道中的选择参数

问题描述 投票:0回答:1

在并行块中使用条件时,我无法回显A或B或C。我已经使用了选择参数。

当我使用全局参数但希望在一个阶段中使用它时,它可以工作。

管道:

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"
                } 
            }
        }
      }
    }
}

错误的输出:

enter image description here

jenkins pipeline declarative
1个回答
0
投票

嗯,我可以通过将阶段级别的参数设置为全局参数,然后将其用于按预期工作的其他阶段来实现。

  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"
            } 
        }
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.