Github – Show current state of Jenkins build on GitHub repo

githubJenkins

Is there a way to show the Jenkins build status on my project's GitHub Readme.md?

I use Jenkins to run continuous integration builds. After each commit it ensures that everything compiles, as well as executes unit and integration tests, before finally producing documentation and release bundles.

There's still a risk of inadvertently committing something that breaks the build. It would be good for users visiting the GitHub project page to know the current master is in that state.

Best Answer

Ok, here's how you can set up Jenkins to set GitHub build statuses. This assumes you've already got Jenkins with the GitHub plugin configured to do builds on every push.

  1. Go to GitHub, log in, go to Settings, Personal access tokens, click on Generate new token.

    screenshot of GitHub settings

  2. Check repo:status (I'm not sure this is necessary, but I did it, and it worked for me).

    screenshot of GitHub token generation

  3. Generate the token, copy it.

  4. Make sure the GitHub user you're going to use is a repository collaborator (for private repos) or is a member of a team with push and pull access (for organization repos) to the repositories you want to build.

  5. Go to your Jenkins server, log in.

  6. Manage JenkinsConfigure System
  7. Under GitHub Web Hook select Let Jenkins auto-manage hook URLs, then specify your GitHub username and the OAuth token you got in step 3.

    screenshot of Jenkins global settings

  8. Verify that it works with the Test Credential button. Save the settings.

  9. Find the Jenkins job and add Set build status on GitHub commit to the post-build steps

    screenshot of Jenkins job configuration

That's it. Now do a test build and go to GitHub repository to see if it worked. Click on Branches in the main repository page to see build statuses.

sceenshot of the main page where you click on 'branches'

You should see green checkmarks:

screenshot of GitHub branches with build status

Related Topic