Skip to content

Instantly share code, notes, and snippets.

@TheTechOddBug
Forked from flmu/Jenkinsfile
Created June 29, 2022 16:00
Show Gist options
  • Save TheTechOddBug/4c454b28f6f17ff43acf7564e274f82e to your computer and use it in GitHub Desktop.
Save TheTechOddBug/4c454b28f6f17ff43acf7564e274f82e to your computer and use it in GitHub Desktop.
Jenkinsfile that creates dynamically stages from a list
def jobs = ["JobA", "JobB", "JobC"]
def parallelStagesMap = jobs.collectEntries {
["${it}" : generateStage(it)]
}
def generateStage(job) {
return {
stage("stage: ${job}") {
echo "This is ${job}."
sh script: "sleep 15"
}
}
}
pipeline {
agent any
triggers {
cron('* * * * *') //cron('15 8 * * *')
}
stages {
stage('non-parallel stage') {
steps {
echo 'This stage will be executed first.'
}
}
stage('parallel stage') {
steps {
script {
parallel parallelStagesMap
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment