Home » Java » Enterprise Java » Continuous Delivery for Heroku With Jenkins

About Andrew Glover

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 our best selling eBooks for FREE!

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

and many more ....

 

Leave a Reply

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

*


× 4 = twenty eight

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.