Does anyone know of any good articles on getting Jenkins to play nicely with Heroku?
What I want to do is:
1) Setup a Jenkins job to poll a private GitHub Repo when check-ins are made to developer branch.
2) Build this branch and make sure everything is good!
3) Push private GitHub Repo codebase to Heroku Repo. So it does the build and deploy on Heroku.
I've seen bits and pieces of articles but can't seem to get the complete flow to work. I've tried the GitHub plugin & Heroku plugin. I CAN get the GitHub plugin to pull down and build but I don't understand how to push to Heroku. Heroku plugin lets me deploy a WAR file but that doesn't bring up the app correctly. So I need to just push the codebase to the Heroku Repo so it does the compile and deploy.
As an alternative to using the Heroku API as outlined above to deploy, you can simply push your code to a remote Git repository (i.e. the one Heroku defined for your app) as a Post-Build Action. Your job would therefore define two Git repositories -- one being your Github repository and another being the Heroku one.
Give the Heroku repository a name, such as 'heroku' and in the Post-Build Actions section, use a Git publisher. Be sure to select the heroku name in the Target Remote name field.
Depending on how you've set up your Build Trigger on your Github project, when a build completes, Jenkins will push the resultant snapshot to the Heroku repository, resulting in a deployment.
I use Jenkins to push to Heroku for our apps. I dont use the Heroku plugin, I like the control that 'Execute Shell' gives me. This is a rather detailed answer, if I missed anything be sure to comment.
1) Polling a Private Repo :
Add the callback URL of your jenkins server (leave that page open for later). Something like :
http://jenkins.example.com/github-webhook/
2) Build the branch. Be sure you have all the GitHub configs set, as the callback will trigger the job only if these settings are done.
3) Push to Heroku. A few things to consider here.
heroku git:remote -a myApp git remote add heroku [email protected]:myApp.git
create an Execute Shell script with just the above, for use only on your first build.
curl https://heroku.newrelic.com/accounts/ACCTID/applications/APPID/ping_targets/disable -X POST -H "X-Api-Key: APIKEY"
Dont forget to turn it back on after:
curl https://heroku.newrelic.com/accounts/ACCTID/applications/APPID/ping_targets/enable -X POST -H "X-Api-Key: APIKEY"
heroku maintenance:on --app myApp heroku maintenance:off --app myApp
Putting this together, a typical deploy script on Jenkins may look like this :
#one off to ensure heroku remote is added to repo heroku git:remote -a myApp git remote add heroku [email protected]:myApp.git #disbales curl https://heroku.newrelic.com/accounts/ACCTID/applications/APPID/ping_targets/disable -X POST -H "X-Api-Key: APIKEY" heroku maintenance:on --app myApp #push to heroku git push --force heroku master heroku run rake db:migrate --app myApp #enables curl https://heroku.newrelic.com/accounts/ACCTID/applications/APPID/ping_targets/enable -X POST -H "X-Api-Key: APIKEY" heroku maintenance:off --app myApp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With