Over a million developers have joined DZone.

Conditional BuildStep Jenkins Plugin for Improving Continuous Delivery Decisions

DZone's Guide to

Conditional BuildStep Jenkins Plugin for Improving Continuous Delivery Decisions

· DevOps Zone ·
Free Resource

Discover a centralized approach to monitor your virtual infrastructure, on-premise IT environment, and cloud infrastructure – all on a single platform.

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.

Learn how to auto-discover your containers and monitor their performance, capture Docker host and container metrics to allocate host resources, and provision containers.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}