DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. Conditional BuildStep Jenkins Plugin for Improving Continuous Delivery Decisions

Conditional BuildStep Jenkins Plugin for Improving Continuous Delivery Decisions

Alex Soto user avatar by
Alex Soto
·
Feb. 13, 13 · Interview
Like (0)
Save
Tweet
Share
11.59K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Continuous Integration/Deployment Delivery (commerce) Jenkins (software)

Published at DZone with permission of Alex Soto, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • ChatGPT Prompts for Agile Practitioners
  • Kotlin Is More Fun Than Java And This Is a Big Deal
  • Java Development Trends 2023
  • The Quest for REST

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: