Skip to content

Instantly share code, notes, and snippets.

@phnahes
Last active October 2, 2020 21:09
Show Gist options
  • Save phnahes/901b92ec00fb4837be28b8088ef03bd5 to your computer and use it in GitHub Desktop.
Save phnahes/901b92ec00fb4837be28b8088ef03bd5 to your computer and use it in GitHub Desktop.
Jenkinsfile - Dinamic stages
#!/usr/bin/env groovy
def list
pipeline {
agent none
stages {
stage('Create List') {
agent any
steps {
script {
//list = ["Test-1", "Test-2", "Test-3", "Test-4", "Test-5"]
/* Services comming from parameterized build vars */
list = "${SERVICE}".split(",");
}
}
post {
cleanup {
cleanWs()
}
}
}
stage('Dynamic Stages') {
agent any
steps {
script {
for(int i=0; i < list.size(); i++) {
stage(list[i]){
echo "Element: $i"
}
}
}
}
post {
cleanup {
cleanWs()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment