Jenkins Declarative Pipeline that Satisfy ALL, one value and multi-value option to run multiple stages

Job ID: 37101416

Budget: $10 – $30 USD

Jenkins pipeline that can accept multiple release values and an ALL option
let's consider pipeline has 4 stages stage1 then stage 2 then stage3 and then stage 4 each is dependent on previous only to complete ex: ALL, 1,2,3,4,5 When we choose ALL, all 4 stages should run in parallel for 1,2,3,4,5 when we choose anyone for ex: 3 then all 4 stages should run in parallel for 3 we also should be able to multiple release values, example: 3 and 5 in this all 4 stages should run in parallel for 3 and 5

I tried matrix, and it's working for ALL options but not for selective, so I had to write duplicate stages for individual ones like below.

But it doesn't support choosing multiple VERSION values, and code is not re-used effectively. Need help with code refactor to run it for multiple options and in parallel


```
pipeline {
agent none

parameters {
string(
name: 'BRANCH',
defaultValue: '',
description: '...')
choice(
name: 'VERSION',
choices: ["ALL", "1", "2", "3", "4", "5"],
description: 'Select version(s) for cluster deploy')
}
stages {
stage('New Cluster') {
when { expression { params.VERSION == "ALL" } }
matrix {
axes {
axis {
name 'BASE_VERSION'
values "1", "2", "3", "4", "5"
}
}
Stages {
stage (1){
...
}
stage (2) {
...
}
stage (n) {
...
}
}
}
}
stage('Desired Version Cluster') {
when {
expression {
params.VERSION != "ALL"
}
}
Stages {
stage (1){
...
}
stage (2) {
...
}
stage (n) {
...
}
}
}
}
}

```
Related categories: Jenkins Continuous Integration DevOps