The DevOps Zone is brought to you by DZone in partnership with Hewlett Packard Enterprise DevOps. Learn where you are in your DevOps journey by taking the HPE/Forrester benchmarking tool.
In Continuous Delivery each build is potentially shippable. This fact implies among a lot of other things, to assign a none snapshot version to your components as fast as possible so you can refer them through all the process.
Usually automated software delivery process consist of several stages like Commit stage, Code Quality, Acceptance Tests, Manual Test, Deployment, ... But let's focusing on the first stage.
The first stage can contain next steps:
- create a release branch
- assign a version to the project
- compile + testing
- packaging (create a war, jar, ...)
But during the execution of one of these steps, a fail may occurs, for example code does not compile or some tests does not pass, and in this case we should delete the created release branch and stop the pipeline execution. On the other hand, if this stage ends successfully, Jenkins should run the next stage defined in pipeline.
To take this decision we are going to use Conditional BuildStep plugin
, which as its name suggests, it allows us to choose which actions to fire depending on result of current job.
So after plugin is installed, we can create a job for the first stage:
So first of all, let's add a new build step (Execute Windows batch command or Execute shell) and launch a git command for creating a branch:git checkout -b helloworld-release-%VERSION_NUMBER%.%BUILD_NUMBER%
In this case we are creating a branch with name of the project, the version number and finally the build number (which is provided by Jenkins).
Next step is to change the version of pom files (keep in mind that we are changing poms of branched project, not the "master") to current version. So let's create a new build step of type "Invoke top-level Maven targets" to invoke Versions Maven plugin.versions:set -DnewVersion=%VERSION_NUMBER%.%BUILD_NUMBER%
Then we can call the clean install goals in a new build step.clean install
Now is where Conditional BuildStep plugin
starts to play:
If current build status is success, which means that code has been compiled and all tests pass, then we must commit the changes and pushing them to remote SCMserver.
So let's create a new build step called Conditional Step (single), and set that if build status is successful, git commands are executed.
But if build fails, the branch should be removed, so let's create a new conditional buildstep in the same build job, which will remove the created branch from current location:
We have learned how to use Conditional BuildStep plugin
to take decisions depending on the status of the current build.
The DevOps Zone is brought to you in partnership with Hewlett Packard Enterprise. Download Through the DevOps Looking Glass: Learnings from HP's Own Transformation Initiative to get valuable best practices and “lessons learned” straight from the HP IT team to help you start or progress along your own DevOps Journey.