Created
December 4, 2019 08:17
-
-
Save flmu/0a0ffbced256201ec08d472316809efa to your computer and use it in GitHub Desktop.
Jenkinsfile that creates dynamically stages from a list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} | |
} | |
} |
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
How to specify different branch name because i'm getting the stage name taken as name of branch
@flmu