英文:
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"}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论