-
-
Save TheTechOddBug/4c454b28f6f17ff43acf7564e274f82e 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 | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment