Continuous Delivery for Heroku With Jenkins

jenkins-logoA continuous delivery pipeline that leverages Jenkins and targets Heroku is fairly simple to set up, provided you install the Jenkins Git plugin. With this pipeline, changes to a specific Git branch will result in a Heroku deployment.

For this deployment process to work nicely, you should use at least two Git branches, as you’ll want to have one branch targeted for auto-deploys and another that doesn’t (as it represents active development). For example, following the git-flow convention, those two branches could be named development and master, where changes to master are deployed to Heroku and changes to development aren’t. Thus, you will have at least two Jenkins jobs that monitor each of these branches.

Naturally, this pipeline process is language agnostic – Node, Ruby, Java – it doesn’t matter what you do during your build as this entire process is choreographed via Git.

When approaching Heroku auto-deployment from Jenkins, don’t bother with Heroku’s API because it’s much easier to use the Git publisher feature of Jenkins to push a branch from your repository to Heroku (which uses Git anyway).

At a high level, you’ll need to define a Jenkins job that monitors your master Git branch; if there are changes, this job will run whatever your build needs to do and as a post-build step you can publish that branch to Heroku. It’s that easy.

To configure this pipeline, you will need the Git plugin. With the Git plugin installed, create a job and in the Source Code management section, add your source Git repository and then add another repository which is the Heroku remote repository.

scm-jenkins1

Be sure to give the Heroku repository a name like heroku. This is done by clicking the Advanced button under the Credentials section.

Second, in the Post-build Actions section, you’ll configure a Git Publisher.

git-pub

In this case, the Git repository you are going to publish to will be the Heroku one defined earlier. Hit the Add Branch button and be sure to indicate the master branch as the Branch to push and the Target remote name should be the name your gave to the remote Heroku repository in the Source Code Management section (i.e. heroku).

scm-jenkins2

Depending on how you’ve set up your Build Trigger on your job, when a build completes, Jenkins will push the resultant snapshot to the Heroku repository, resulting in a deployment! Now wasn’t that easy, man?
 

Reference: Continuous Delivery for Heroku With Jenkins from our JCG partner Andrew Glover at the The Disco Blog blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


− three = 1



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close