Skip to content

Instantly share code, notes, and snippets.

@flmu
Created December 4, 2019 08:17
Show Gist options
  • Save flmu/0a0ffbced256201ec08d472316809efa to your computer and use it in GitHub Desktop.
Save flmu/0a0ffbced256201ec08d472316809efa 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
}
}
}
}
}
@aym0406
Copy link

aym0406 commented Jan 19, 2021

How to specify different branch name because i'm getting the stage name taken as name of branch
@flmu

@flmu
Copy link
Author

flmu commented Jan 29, 2021

@aym0406

Have you found a solution to your problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment