Skip to content

overmobile/jenkins-comments

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Things you'll need

We'll pretend the following:

  • You have a Jenkins install at http://jenkins.mycompany.com
  • You have a GitHub organization called overmobile
  • You have a GitHub account called overmobile-jenkins
  • You have a repo you'd like pull requests on called captains

Initial setup

Clone the repo locally

git clone git@github.com:overmobile/jenkins-comments.git
cd jenkins-comments 

Create a Heroku application

First we'll need a Heroku app running their Cedar stack, and a Redis server. We'll also set the url of our Jenkins server. Chose a name (we'll use "mycompany-jenkins-comments" for the example), and create it:

heroku create overmobile-jenkins-comments --stack cedar
git push heroku master

heroku addons:add redistogo:nano

heroku config:add JENKINS_URL=http://jenkins.mycompany.com
heroku config:add NODE_ENV=production

heroku ps:dynos 1

Setup your app with permissions for GitHub

Create a new Authorization using the GitHub Authorizations API:

curl -u "overmobile-jenkins:password" https://api.github.com/authorizations \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{"scopes":["repo"],"note": "overmobile-jenkins-comments.herokuapp.com"}'
{
  "scopes": [
    "repo"
  ],
  "updated_at": "2012-05-21T16:33:05Z",
  "note_url": null,
  "app": {
    "url": "http://developer.github.com/v3/oauth/#oauth-authorizations-api",
    "name": "overmobile-jenkins-comments.herokuapp.com (API)"
  },
  "url": "https://api.github.com/authorizations/369874",
  "token": "a55199221f3f66a7d238be5fa32e2cd84735ffc1",
  "note": "mycompany-jenkins-comments.herokuapp.com",
  "created_at": "2012-05-21T16:33:05Z",
  "id": 369874
}

In the reponse is the token the app will use to comment on pull requests. Add that token to Heroku:

heroku config:add GITHUB_USER_TOKEN=a55199221f3f66a7d238be5fa32e2cd84735ffc1

Per repo

Configure Jenkins Job

Under Build > Inject environemnt variables > Properties Content, set BUILD_STATUS to success. This will only be set if the build succeeds:

BUILD_STATUS=success

In Post-build Actions > Post build task > script, we'll add a curl statement to post the job status to mycompany-jenkins-comments.herokuapp.com:

curl "http://overmobile-jenkins-comments.herokuapp.com/jenkins/post_build\
?user=overmobile\
&repo=captains\
&sha=$GIT_COMMIT\
&status=$BUILD_STATUS\
&job_name=captains\
&job_number=$BUILD_NUMBER"

Configure GitHub to notify us of an opened pull request

We'll use the GitHub PubSubHubBub API to subscribe to pull requests events:

curl -u "overmobile-jenkins:password" https://api.github.com/hub \
  -Fhub.mode=subscribe \
  -Fhub.topic=https://github.com/overmobile/captains/events/pull_request \
  -Fhub.callback=http://overmobile-jenkins-comments.herokuapp.com/github/post_receive

Releases

No releases published

Packages

No packages published

Languages

  • CoffeeScript 99.2%
  • JavaScript 0.8%