Show current state of Jenkins build on GitHub repo

前端 未结 12 1557
遥遥无期
遥遥无期 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:44

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

    You should be able to embed badges like this into your README.md file:

    build passing

    0 讨论(0)
  • 2020-11-28 17:49

    Edit:

    I'm no longer using this approach, please use one of the other answers.

    Update: what I ended up doing, for our specific case: (above answers were great - thanks!)

    Because our build server is not on the internet, we have a script to publish the build status to the gh-pages branch in github.

    • Start of build stamps failing
    • End of build stamps success
    • Project runs after main project to publish results -> build-status, API docs, test reports and test coverage.

    GitHub caches images, so we created .htaccess file, that instructs a short cache timeout for the build-status image.

    Put this in the directory with the build-status image:

    ExpiresByType image/png "access plus 2 minutes"
    

    Here's the build script. The target that publishes to gh-pages is '--publish.site.dry.run'

    With less than 400 lines of config, we have:

    • Compile checks
    • unit & integration tests
    • Test Reports
    • Code Coverage Reports
    • API Docs
    • Publishing to Github

    . . and this script can be run in or outside of Jenkins, so that:

    • Developers can run this script before commit, reducing the chance of a broken build that impacts others.
    • A failure is easy to reproduce locally.

    The Results:

    Project main page has the build status, updated after each build, along with latest API Docs, test results and test coverage.

    0 讨论(0)
  • 2020-11-28 17:51

    Add below line in your README.md and change both URL according to your jenkins project.

    [![Build Status](https://jenkins../..project/lastBuild/buildStatus)](https://jenkins../..project/lastBuild/)
    
    0 讨论(0)
  • In regards with setting up Jenkins and GitHub's protected branch. I'm using Jenkins 2.6, and these are the steps I did to make it work:

    On your repository's GitHub webpage:

    1. Navigate to Settings > Branches.
    2. Under Protect branches, click on the Choose a branch drown down menu and select the branch you want to set as a Protected branch.
    3. Enable the options as needed.

    On the Jenkins Server: (Make sure you have the Git and GitHub Plugin installed)

    1. Navigate to Manage Jenkins > Configure System.
    2. Under GitHub, set the API URL to https://api.github.com. Though this is the default value.
    3. Select your generated token for the Credentials. If you haven't generated a token yet, click on Advanced... then on Additional actions, you can convert your login and password to token and use it as your credential.

    Also, make sure the GitHub account that your Jenkins is using is a collaborator for the repository. I've set it with write permission level.

    Hope this helps.

    0 讨论(0)
  • 2020-11-28 17:54

    In the meanwhile the UI of Jenkins and GitHub has changed a bit and it took me a while to figure out how to configure Jenkins now correctly. The explanation here is based on Jenkins version 2.121.1.

    I also assume that you have already configured your Jenkins Job be triggered by a webhook or by polling. Those are the steps that I have taken to get it working:

    1. Configure Github: Create Personal Access Token with OAuth Scope repo:status
    2. Configure Jenkins: Configure System and add the OAuth Secret as a GitHub Server - use Secret Text as an authentication method to put the OAuth Secret in there.
    3. Configure your Jenkins Job: Add Set GitHub commit status as Post-build action. Set the Status Result to One of the default messages and statuses.
    4. Check your result on GitHub: Check if you get the build status and build execution duration on your GitHub commit.

    Configure Github





    Configure Jenkins






    Configure Jenkins Job




    Result

    You will now see the status for your commits and branches:

    0 讨论(0)
  • 2020-11-28 17:58

    Jently updates your Github commit status (as described by @vonc above), unfortunately they have yet to implement the Repo Status API

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