Show current state of Jenkins build on GitHub repo

前端 未结 12 1558
遥遥无期
遥遥无期 2020-11-28 17:34

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

相关标签:
12条回答
  • 2020-11-28 17:59

    I followed the directions from Alex and it worked.

    But, for GitHub Enterprise you need to modify the API URL when adding the server to Jenkins.

    For example, if your company is creditcard.com, your URL would be

    https://github.creditcard.com/api/v3/

    0 讨论(0)
  • 2020-11-28 18:00

    What I did is quite simple:

    1. Install the Hudson Post Task Plugin
    2. Create a Personal Access Token here : https://github.com/settings/tokens
    3. Add a Post Task Plugin that always put success

      curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{
        \"state\": \"success\",
        \"target_url\": \"${BUILD_URL}\",
        \"description\": \"The build has succeeded!\"
      }"
      
    4. Add a Post Task Plugin that will put failure if "marked build as failure"

      curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{
        \"state\": \"failure\",
        \"target_url\": \"${BUILD_URL}\",
        \"description\": \"The build has failed!\"
      }"
      
    5. You can also add a call to pending at the beginning of tests

      curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{
        \"state\": \"pending\",
        \"target_url\": \"${BUILD_URL}\",
        \"description\": \"The build is pending!\"
      }"
      

    Screenshot of the Post build task configuration

    0 讨论(0)
  • 2020-11-28 18:02

    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

    0 讨论(0)
  • 2020-11-28 18:03

    There's also this plugin that will give you a badge url that you can post in your README.md and looks like this

    build passing

    https://wiki.jenkins-ci.org/display/JENKINS/Embeddable+Build+Status+Plugin

    0 讨论(0)
  • 2020-11-28 18:05

    If you have Github plugin installed on your Jenkins, you can do it in the Post build actions like this :

    set build status on github

    0 讨论(0)
  • 2020-11-28 18:07

    The Commit Status API allows you to see the "Repo Statuses API".

    And since April 26th 2013, you now can see the build status on your GitHub repo branch page:

    build status on GitHub repo branches

    That means it is another way, by visiting the GitHub project page, to see those statuses instead of having only Jenkins.

    Starting April 30th, 2013, the API endpoint for commit statuses has been extended to allow branch and tag names, as well as commit SHAs.

    0 讨论(0)
提交回复
热议问题