The Workflow plugin is an open source plugin (or paid plugin available with Enterprise Jenkins by Cloudbees) that solves the challenge of complex build and delivery pipelines in Jenkins, and does so by using a Groovy DSL. Packaged with the core Workflow plugin, are other supporting plugins that increase the usefulness of the Workflow plugin. The first supporting plugin is the Stages plugin which allows you to define stages as conceptual boundaries in your workflow, and allows for marking if a stage can run in concurrency or not. For example, if you have a workflow that builds your application, deploys it, and runs front end GUI tests, you could break this into three obvious stages (build, deploy, test), and might not want your deploy step to run concurrently. The DSL for this is very simple:

stage 'Build'
node('build-node'){
      //build your app
}
stage 'Deploy', concurrency: 1
node('deploy-node'){
      //deploy your app
}
stage 'Test'
node('test-node'){
      //run your automated tests
}

Workflow also allows for visualization of the stages, which makes it easier for developers to see where their commits have gone.

The next feature within the Workflow suite, is the idea of checkpoints. The idea of a workflow checkpoint is the same as in a video game, if you die, you can start over from the checkpoint. For example, if your automated test suite fails due to a flaky test (and the developer refuses to fix the flakiness), you could always rerun it. Of course this adds a little more complexity to our pipeline and the corresponding code would be:

stage 'Build'
node('build-node'){
      //build your app
}
steps.checkpoint('Deploy')
stage 'Deploy', concurrency: 1
node('deploy-node'){
      //deploy your app
}
steps.checkpoint('Test')
stage 'Test'
node('test-node'){
      //run your automated tests
}

This code would allow for you to either redeploy, or retest your application. This could be very useful if your application takes a very long time to build, and you don’t want to rebuild every time a deploy, or a (flaky) test fails.

There is much more to the Workflow that I have to write about, please stay tuned for the next installment!

Leave a comment

Your email address will not be published. Required fields are marked *

X