Skip to content

Instantly share code, notes, and snippets.

@anandbn
Created June 6, 2012 18:12
Show Gist options
  • Save anandbn/d07742432f712bcf2786 to your computer and use it in GitHub Desktop.
Save anandbn/d07742432f712bcf2786 to your computer and use it in GitHub Desktop.
Cloudbees - Heroku WAR Deploy - How to

Deploying to Heroku from Cloudbees

Pre-requisites

[1] Get a Cloudbees account. You will need an Pro or Enterprise account so that custom plugins can be installed in the Jenkins (Dev@Cloud).

Edition

[2] A Heroku account. Sign up here

[3] Heroku pluin for Jenkins : Once you have an enterprise Cloudbees account, open a support ticket to have them install the "Heroku plugin". The Heroku plugin is available at https://wiki.jenkins-ci.org/display/JENKINS/Heroku+Plugin

Note: Please make sure the plugin version is 0.3-BETA

Setting up a Code repository

[1] Create a new Repository: For this demo we'll use a Git repository form Cloudbees. If you are more familiar with SVN choose the same and some of the below steps would change appropriately.

Create new Repository

[2] Add you public key to Cloudbees (Note: This is required so that you can commit code to Cloudbees's repository over SSH).

Add SSH key to Cloudbees

Create a simple Web application

You can use a simple Spring MVC Hibernate application from this [Git Repo] (https://github.com/anandbn/spring-mvc-heroku) if you do not have an existing web application.

Using an Existing web application

Refer to the Tomcat web app runner dev center article on how to get your WAR project working with Tomcat webapp runner.

Testing locally

To make sure your application runs fine locally, use the following commands

$ mvn package

$ java -jar target/dependency/webapp-runner.jar target/*.war

Add the Cloudbees Repo as Remote Repository

[1] Create Git Remote: Git -> Repositories -> YourAppRepo > Remotes > Create Remote

[2] Enter the Git URL from the repository that you created in cloudbees. This will typically be of the format:

ssh://git@git.cloudbees.com/[username]/[repo_name].git

[3] Save and Push the code to the cloudbees remote repository.

Refer to cloudbees documentation for SVN specific steps.

Heroku API key to the Jenkins Setup

[1] Add API Key: Manage Jenkins > Configure System > Default Heroku API Key.

Heroku API Key setup

You can get your Heroku API key here.

Creating a new Jenkins Job

[1] Create Job: Choose "Freestyle project" as the Heroku plugin is not visible for the other types of jenkins jobs.

Free style project

[2] Configure "Source Code Management" section and select "Git" & add your Git Repo URL from the repository that you created above.

Source Code Rpository

[3] Build Triggers: Select "Build when a change is pushed to CloudBees Forge" in the "Build Triggers" section

Build Trigger

Build step 1: Create your WAR

[4] Create a new Build step and select "Invoke top level Maven goal"

Maven Build

[5] Enter "package" (this is the maven goal that will be run. This is equivalent of jenkins running mvn package)

![Maven goal] (https://gist.github.com/raw/2884906/a621e78ef9cb466ba5529cd43e76252d315290ce/cbess_build_1_maven.png.png)

Build step 2: Deploy your WAR to Heroku

[6] Create a new Build step and select "Heroku: Deploy WAR artifact"

[7] Enter the following information:

  • App name: This is a required field. Enter a name for the app on Heroku. If the app name does not exist, the deploy will automatically create it for you as long as the name is not already taken

  • WAR Path: Enter target/[artifactId].war

  • API Key: This is optional attribute and the default API key will be used if this is left empty.

Heroku WAR Deploy

Test your Jenkins/Heroku deploy setup

[8] Make a change to your source code, and push the changes to the "cloudbees" remote repository. Your build should automatically kick off and deploy to Heroku.

For the 1st time you deploy you should see:

Created new app: [app-name]
Preparing to deploy WAR to [app-name]
Adding war => target/[artifactid].war
Deploying...
message:created release
release:v4
status:success
Deployment successful: http://[app-name].herokuapp.com/
Finished: SUCCESS

For subsequent updates to your code should see the following:

Found existing app: [app-name]
Preparing to deploy WAR to [app-name]
Adding war => target/[artifactid].war
Deploying...
message:created release
release:v5
status:success
Deployment successful: null
Finished: SUCCESS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment