Demo for my talk - Synchronizing parallel delivery flows in Jenkins using Groovy, BuildFlow and a bit of black magic
Groovy
Synchronizing parallel delivery flows in Jenkins using Groovy, BuildFlow and a bit of black magic
What is included
Dockerfile - Thin docker build file. All magic is done in Jenkins official build file. I'm only providing list of plugins to install and few groovy scripts for initial configuration
plugins.txt - list of plugins that will be automatically installed. All versions of the plugins fixed as well as Jenkins version in order to ensure reproducibility of the setup as time goes.
job-dsl - JobDSL plugin. Required to generate jobs used for demo
build-flow-plugin - BuildFlow plugin. Required to orchestrate jobs execution
buildgraph-view - Build Graph View Plugin. We don't really need it for the demo. Just in case if I will need to show how jobs connected as a graph.
quietperiod.groovy - set global Quiet Period to 0
executors.groovy - set number of executors on master to 0
createjob.groovy - create a JobDsl seed job. This one is a tricky one. Apparently it is not that simple to create job in Jenkins on startup. There is a possibility to just copy config.xml. But IMHO doing that in Groovy is a bit more elegant despite of some effort required to look up type for the JobDSL builder. Also this way allows to avoid mess with file permission after copy of xml file. Main idea of this file is to create a seed job with JobDSL inside so we can generate all jobs during demo without wasting time on configuration.
cd jenkins-checkpoints-demo
docker build -t checkpoints-demo .
Kick off new container
docker run -p 8080:8080 checkpoints-demo
After few seconds you should be able to see Jenkins page in your browser at localhost:8080! Time to do things!
Demo
Open localhost:8080 in your browser and run seedjob. Seedjob will generate all necessary jobs. We have two types of jobs - trigger and build steps. Trigger is a buildflow that orchestrate jobs execution and step-x jobs. Those are just dummy ones that will hang for a random number of seconds passed as parameter from the build flow.
Open build flow configuration. You can see that we create a CheckPoint before starting step-5. That will allow us to sync jobs and ensure execution order. We also will set description for every run in order to provide better visibility to what flow this execution belongs to
Kick off 10-20 trigger executions and watch order of step-4 executions. You will notice that some sessions will reach that step faster than other but still will wait for previous flows to finish before start step-5
That is basically it. Now you only limited with you imagination :) Go hack it!