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.
Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

Leave a Reply


8 − six =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
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.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books