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

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

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

问题

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

  1. pipeline {
  2. parameters {
  3. choice choices: ['ME', 'FC', 'ME_and_FC'], description: '选择一个', name: 'Build_type'
  4. }
  5. agent {
  6. node {
  7. label 'Slave_APP_Train_32'
  8. customWorkspace 'App_WS'
  9. }
  10. }
  11. stages {
  12. stage('FC') { steps { echo "D6-EPS已执行" } }
  13. stage('FC') { steps { echo "D6-EPS已执行" } }
  14. stage('FC') { steps { echo "D6-EPS已执行" } }
  15. stage('parallel') {
  16. parallel {
  17. stage('ME') {
  18. stages {
  19. stage('D6 SRA') { steps { echo "D6-EPS已执行" } }
  20. }
  21. }
  22. stage('ME') {
  23. stages {
  24. stage('D6 EPS') { steps { echo "D6-EPS已执行" } }
  25. }
  26. }
  27. stage('ME') {
  28. stages {
  29. stage('C3 EPS') { steps { echo "D6-EPS已执行" } }
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }

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

英文:
  1. pipeline {
  2. parameters {
  3. choice choices: ['ME', 'FC', 'ME_and_FC'], description: 'Pick Something', name: 'Build_type'
  4. }
  5. agent {
  6. node{
  7. label 'Slave_APP_Train_32'
  8. customWorkspace 'App_WS'
  9. }
  10. }
  11. stages {
  12. stage('FC') { steps {echo "D6-EPS EXECUTED"}}
  13. stage('FC') { steps {echo "D6-EPS EXECUTED"}}
  14. stage('FC') { steps {echo "D6-EPS EXECUTED"}}
  15. stage('parallel'){
  16. parallel {
  17. stage('ME') {
  18. stages {
  19. stage('D6 SRA') { steps {echo "D6-EPS EXECUTED"}}
  20. }
  21. }
  22. stage('ME') {
  23. stages {
  24. stage('D6 EPS') { steps {echo "D6-EPS EXECUTED"}}
  25. }
  26. }
  27. stage('ME') {
  28. stages {
  29. stage('C3 EPS') { steps {echo "D6-EPS EXECUTED"}}
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }`

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

  1. I tried by calling with this command if(${params.Build_type=='ME'}||${params.Build_type=='ME_and_FC'})
  2. [ERROR](https://i.stack.imgur.com/x0BWA.png) it shows like not a valid syntax
  3. Can someone help me to figure it out`

答案1

得分: 0

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

示例:

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

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

example:

  1. stage('FC') {
  2. when { expression { return params.Build_type == 'FC' } }
  3. steps {
  4. echo "D6-EPS EXECUTED"}
  5. }
  6. }

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:

确定