Jenkins build status icons on GitHub Pull requests - github

I am integrating Jenkins with GitHub and have successfully set Jenkins to build after a GitHub push. But another thing I would like to establish is the build status icons(green check, yellow circle for pending, red "x") on the Pull request page. How do I go about to show these icons?
Here's an example from apple's swift pull request page:

In order to do this, you need to add Jenkins plugins:
github-request-builder sets the build status of a given PR in GitHub. This post is a good guide for setting it up.
embeddable-build-status hosts a project-wide image showing your overall build status:

Related

Showing ConcourseCI build status on github pull requests

I currently have a fully functioning pipeline that's been deployed to a concourse server. It will receive push events from a github repo, and run the pipeline as such.
I have a webhook that's also able to talk from github to the concourseCI server.
It looks something like this:
https://concourse.myorganization.app/api/v1/teams/my_team/pipelines/git-repo-name/resources/git-repo-pull-requests/check/webhook?webhook_token=some_token
I have it dropped into the settings of the Github repo as a webhook, and it's returning 2xx after each push to a pull request. How can I get the status of the build in ConcourseCI to show up on the pull request like this
GitHub build status is independent from the webhook: the webhook goes from GitHub to Concourse, while here we need the opposite direction: from Concourse to GitHub. Also, it cannot be synchronous, since the webhook triggers a build that takes time to complete.
You need to signal the build status with a Concourse resource. The one I prefer (since I wrote it :-) is https://github.com/Pix4D/cogito.

Show Travis-CI build status on Github Pull Request Page

How do you configure Github's pull request review page to show Travis-CI build status?
I remember Github automatically showing build status for some of my repos configured to build using Travis-CI, but Github has stopped doing this. Whether the build passed or succeeded, Github would show the status near the "Merge pull request" button. Now I have to manually search for the pull request in Travis-CI.
Has this feature been discontinued by Github, or is there some new manual configuration needed to re-implement this?
This discussion thread explained the issue.
The solution was to:
revoke access to Travis-CI in Github
logout of Travis-CI
log back in to Travis-CI.
Travis-CI then automatically asked for Github credentials, and afterwards Github again shows Travis-CI build status in a check.
The legacy integration has been disabled and you need to perform the migration to the GitHub app integration. See the instructions here: https://docs.travis-ci.com/user/migrate/legacy-services-to-github-apps-migration-guide/
Note that if you are not the owner on the repo, you will need to request adding Travis access to the appropriate person.

Using a jenkins pipeline to build github pull requests

This seems to be one of the more important, but less understood and documented features of GH and Jenkins, which seems to defeat the purpose of CI entirely ...
I'm trying to setup a simple, "kick off a build when a pull request is opened" Job in Jenkins. I've scanned though dozens of posts, some several years old, but have yet to find a solution that actually works, start-to-finish. I'm using GH 2.15.4 and Jenkins 2.89.3 with the GH Pull Request Builder plug-in. I've tried setting up a pipeline job, and a freestyle project, following various "how to" posts and docs. Nothing works as expected. Not even close. I've managed to get some functionality working, but not without a lot of trial-and-error experimenting, which doesn't leave me with a warm-fuzzy in using it. Webhooks are equally worthless in accomplishing what is needed, as nothing seems to fire off a job in Jenkins, regardless of how it is configured.
For starters, are there any references or docs that explain what the following status checks are that are automatically created by Jenkins:
continuous-integration/jenkins/branch
continuous-integration/jenkins/pr-head
continuous-integration/jenkins/pr-merge
Apparently there is no way to delete or edit these ... they just "appear" courtesy of Jenkins. I've seen some discussions, but some explanations contradict one another, so they may just be outdated, inaccurate, etc. I want to know "what does what" so I know which should be 'required' as part of the PR status check.
Any pointers would be appreciated!
I agree, this problem is tricky because Jenkins and its plugins have changed so much throughout the years. Let me tell you how I accomplished what you're asking for. I will post all of my version numbers (mostly up to date).
Jenkins Version: 2.176.1 (java -jar /usr/share/jenkins/jenkins.war --version)
Plugins
github 1.29.4
github-api 1.9
github-branch-source 2.5.3
github-pullrequest 0.2.5
pipeline-github-lib 1.0
Also, I use the Blue Ocean interface, which might affect things (who knows)
blueocean 1.17.0
blueocean-git-pipeline 1.17.0
blueocean-github-pipeline 1.17.0
Github Webhooks
First off, set up webhooks for your system. This is a good guide for Github Webhooks
Go to your Github repository and click on the Settings tab. Then select 'Webhooks' in the left menu:
The URL of my Jenkins setup is https://jenkinsci.dorian.com. So, in the 'Payload URL' box, I put https://jenkinsci.dorian.com/github-webhook/
I left the settings as "application/json" and "send me everything" and "active"
The Webhooks area has a handy 'Recent Deliveries' section which can show you if your webhooks are making it to Jenkins. At first, I had the wrong URL so mine has red Xs next to them. Now, they're all green checkmarks.
Github Access Token
Many guides suggest that you provide Jenkins with a personal access token to communicate with your repo. To do that, go to your account avatar in the top right and select Settings -> Developer Settings -> Personal access tokens->Generate Token
Put whatever you want for the description. Under 'select scopes', if you just want it to work, select every checkbox in the list.
I selected:
repo:status
write:repo_hook
read:repo_hook
admin:org_hook
Click save and you'll be shown your secret key. Copy this somewhere safe (we'll use it soon).
Configuring Jenkins
Now for the hard part. Try and install all of the plugins I've listed above.
Go to Jenkins-Manage Jenkins->Configure System
Locate the Github section and click Add Github Server
Name: Github
Api URL: https://api.github.com
Manage Hooks: true
Under credentials, click "Add." You'll be brought to a menu. Select "Secret Text"
Scope: Global
Secret: paste your access token from earlier
ID: (I left this blank)
Description: DorianGithubCreds
Hit save. Then, select DorianGithubCreds from the credentials list.
To test, hit "Test Connection." Mine returns 'Credentials verified for user dnrahamim', rate limit: 4998
Now go down to Github Pull Request Builder
GitHub Server API URL: https://api.github.com
Jenkins URL override: (blank)
Shared Secret: (blank)
Credentials: DorianGithubCreds
Auto-manage webhooks: true
Everything else is blank
Configure Job
Go to the job that should be building your repo
Select 'Configure' in the left menu
Under Projects->Github Organization
Credentials: DorianGithubCreds
Owner: Dorian
Behaviors:
Discover branches
Strategy: Exclude branches that are also filed as PRs
Discover pull requests from origin
Strategy: Merging the pull request with the current target branch revision
Discover pull requests from forks
Strategy: Merging the pull request with the current target branch revision
Trust: From users with Admin or Write permission
Project Recognizers
Pipeline Jenkinsfile
Path: Jenkinsfile (my Jenkinsfile is in the project root)
Build Strategies: (intentionally blank)
Notifications
Now, when I do a pull request, or whenever I post a change to a pull request, Jenkins run a fresh build for that branch.
The Pull Request itself in Github also lists its "Status Checks" at the bottom. When the build is pending, the status check is yellow. If it succeeds it gets a green checkmark. If it fails, it gets a red X.
I initially had a problem because I had an old Jenkins box which was also configured to manage Github webhooks and build pull requests. Its builds were failing so its notifications were the ones getting through to my pull request. I fixed that problem by preventing that old Jenkins box from building my newest branches. Once the old Jenkins box stopped building, the notifications from the new Jenkins box made it through to Github.
Wrapping up
That's it! That's everything I intentionally configured. Please try out my configuration and see if it works for you. Let me know if I left anything out.
The hard part with configuring Jenkins with Github is that, although there are many guides, the suggestions often conflict with each other and very many are out of date (sometimes even official documentation is out of date).
Nonetheless, here are some Resources:
This is a good guide for Github Webhooks
Github's Whitepaper on CI with Jenkins (It doesn't explain much in detail but it gives a good overview)
Github pull request builder plugin
Semi-official SO post for showing build status on Github repo
GitHub has "add webhook" feature which is accessible in the repository settings --> Webhooks section. This has 4 inputs
1. Payload URl - Enter the Jenkins url
2. Content Type - application/json
3. Secret - this is optional if you want to configure secret
4. Which events would you like to trigger this webhook? - select the option "Let me select individual events"
Bunch of checkbox options are visible, check "Pull requests" option. This option will send a request to Jenkins when Pull request is opened
Next step is create a job in Jenkins which will listen to GitHub events and kick off the build

Github multiple status checks for pull request

I have a teamcity project running a build against github repo. On completion of the build, it uses a build feature of teamcity named "Report Change Status to Github" which reports the build status using - https://api.github.com
Now I would like to have another teamcity project run a build against the same github repo and report the build status to github.
How do I make github display the 2 status checks differently? Despite the 2 builds reporting status to github, github just displays "1 pending check" or "1 status check completed successfully"
Edit: I didn't realize you already have the plug in installed, but I am going to leave the steps for other users. I think you need separate build configurations and to make sure you customize the context setting.
I was playing with this today and you can't use JetBrains "Commit Status Reporter" to do this. You can use this plugin though: https://github.com/jonnyzzz/TeamCity.GitHub
It wasn't straightforward to install--
Go here (choose Log in as guest): https://teamcity.jetbrains.com/viewType.html?buildTypeId=bt398 and
Click the "View" link in the "Artifacts" column in the latest successful build.
Then you click teamcity.github.zip and it will download a zip file
Then you upload that zip to TeamCity in the plugins section
Once you do that, go to Build Features and click "Add Build Feature" and select "Report change status to GitHub".
Then fill the form out with something like this (Note: You will need this for each build configuration you want reported. I am also running each build on separate agents which might be necessary):
Statuses are created with something called a context:
https://developer.github.com/v3/repos/statuses/#create-a-status
For each commit, the latest status for each context is shown. And for the pull request overall (next to the merge button) the latest per-context statuses of the latest commit in the pull request are shown.
This means that if you want multiple status checks to show up -- those statuses need to be created with different contexts. And that's something defined by the application which is creating statuses, not GitHub. GitHub only displays the statuses.

How to make GitHub correctly show the build status image of the Jenkins Build Status plugin

Here's an example of a project:
https://github.com/storm-enroute/macrogl
The README.md of this project contains a build status image from a Jenkins running on a server somewhere else:
[![Build Status](https://ci.storm-enroute.com:8080/job/public-macrogl/badge/icon)](https://ci.storm-enroute.com:8080/job/public-macrogl/)
This image is rendered perfectly in Stackoverflow and Github static pages, but on the Github website it is cached to the content delivery network called Fastly. Opening the image URL shows "Not found".
Why is this happening?
How do I have the Github web interface render a markdown with such an image correctly?
How do I have the Github web interface render a markdown with such an image correctly?
The syntax is correct.
Some other project leverage such feature (see LibGit2Sharp Readme or libgit2 Readme for instance).
Why is this happening?
Few seconds ago, https://ci.storm-enroute.com:8080/job/public-macrogl/badge/icon was returning a 404 for me. It looks now fixed.
However, there's a possibility that when the CI server is offline/can't be reached, the 404 is temporarily cached by Camo and served until the cache expires.
install jenkins plugin for embeddable-build-status from: https://plugins.jenkins.io/embeddable-build-status
add to your README.md the tags you want:
Plain Link (with view)
http://URL:8080/buildStatus/icon?job=JOB_NAME
Plain Link (without view)
http://URL:8080/buildStatus/icon?job=JOB_NAME
Markdown (with view)
Build Status http://URL:8080/buildStatus/icon?job=JOB_NAME
Markdown (without view)
Build Status http://URL:8080/buildStatus/icon?job=JOB_NAME
3.Configure jenkins security to allow the status view:
Manage Jenkins -> Configure Security -> Authorization -> choose matrix-based security and check the "ViewStatus" box for the Anonymous user.
if admin user is not there, add it and give it permission to all the boxes.
For anyone else spending way more time than intended on this and wanting a little clarity on what link(s) to use after installing the Emeddable Build Status plugin:
If you navigate to the job in the Jenkins (jenkins_home >> repo >> project >> branch), there's a "Emeddable Build Status" widget you can click on the left pane, and it'll show list exactly what links you can use for your specific jobs.
The following URL structure might also get you to the embeddable build status page:
https://<jenkins_host>/job/<github_owner_or_org>/job/<github_repo_name>/job/master/badge/
Update: I had a similar issue. It turned that the cache server requires the image to be hosted behind a HTTPS, with a fully valid SSL certificate chain (CA(s) + cert). Once your server provides the full cert chain, github will display your badge.