Implementing conditional execution of Jenkins pipeline stages based on the ‘choice’ parameter.

huangapple go评论61阅读模式
英文:

Implementing conditional execution of Jenkins pipeline stages based on the 'choice' parameter

问题

以下是您要翻译的代码部分:

pipeline {
    parameters {
        choice choices: ['ME', 'FC', 'ME_and_FC'], description: '选择一个', name: 'Build_type'
    }
    agent {
        node {
            label 'Slave_APP_Train_32'
            customWorkspace 'App_WS'
        }
    }
    stages {
        stage('FC') { steps { echo "D6-EPS已执行" } }
        stage('FC') { steps { echo "D6-EPS已执行" } }
        stage('FC') { steps { echo "D6-EPS已执行" } }
        stage('parallel') {
            parallel {
                stage('ME') {
                    stages {
                        stage('D6 SRA') { steps { echo "D6-EPS已执行" } }
                    }
                }
                stage('ME') {
                    stages {
                        stage('D6 EPS') { steps { echo "D6-EPS已执行" } }
                    }
                }
                stage('ME') {
                    stages {
                        stage('C3 EPS') { steps { echo "D6-EPS已执行" } }
                    }
                }
            }
        }
    }
}

请注意,代码中的注释和错误信息没有进行翻译。如果您需要进一步的帮助,可以提出具体问题。

英文:
 pipeline {
  parameters {
choice choices: ['ME', 'FC', 'ME_and_FC'], description: 'Pick Something', name: 'Build_type'
 }
  agent {
    node{
        label 'Slave_APP_Train_32'
        customWorkspace 'App_WS'
    }
 }
stages {
    stage('FC') { steps {echo "D6-EPS EXECUTED"}}
    stage('FC') { steps {echo "D6-EPS EXECUTED"}}
    stage('FC') { steps {echo "D6-EPS EXECUTED"}}
      stage('parallel'){
          parallel {
            
            stage('ME') {
                stages {
                    stage('D6 SRA') { steps {echo "D6-EPS EXECUTED"}}
                   
                }
            }
            stage('ME') {
                stages {
                    stage('D6 EPS') { steps {echo "D6-EPS EXECUTED"}}
                   
                }
            }
            stage('ME') {
                stages {
                    stage('C3 EPS') { steps {echo "D6-EPS EXECUTED"}}
                   
                }
            }
        }
      }
    
    }
  }`

Need some conditional statement to call the ME and FC stages ,so that it runs based on the choices given in the choice parameter

This my script, i am not sure how to call the choice parameter with if condition
Say for FC all the FC stages should run , for ME all the ME stages should run

I tried by calling with this command if(${params.Build_type=='ME'}||${params.Build_type=='ME_and_FC'})
 [ERROR](https://i.stack.imgur.com/x0BWA.png) it shows like not a valid syntax 

Can someone help me to figure it out`

答案1

得分: 0

你可以使用 when 块来实现这一点,参见Pipeline Syntax

示例:

stage('FC') {
   when { expression { return params.Build_type == 'FC' } }
   steps {
      echo "D6-EPS EXECUTED"
   }
}
英文:

you can use the when block for this see Pipeline Syntax.

example:

stage('FC') {
   when { expression { return params.Build_type == 'FC' } }
   steps {
      echo "D6-EPS EXECUTED"}
   }
}

huangapple
  • 本文由 发表于 2023年5月21日 15:22:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76298736.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定