[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).
[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
[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.
[2] Add you public key to Cloudbees (Note: This is required so that you can commit code to Cloudbees's repository over SSH).
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.
Refer to the Tomcat web app runner dev center article on how to get your WAR project working with Tomcat webapp runner.
To make sure your application runs fine locally, use the following commands
$ mvn package
$ java -jar target/dependency/webapp-runner.jar target/*.war
[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.
[1] Add API Key: Manage Jenkins > Configure System > Default Heroku API Key.
You can get your Heroku API key here.
[1] Create Job: Choose "Freestyle project" as the Heroku plugin is not visible for the other types of jenkins jobs.
[2] Configure "Source Code Management" section and select "Git" & add your Git Repo URL from the repository that you created above.
[3] Build Triggers: Select "Build when a change is pushed to CloudBees Forge" in the "Build Triggers" section
[4] Create a new Build step and select "Invoke top level Maven goal"
[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)
[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
: Entertarget/[artifactId].war
-
API Key
: This is optional attribute and the default API key will be used if this is left empty.
[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