Jenkins/GitHub Integration

This page explains how to integrate Jenkins builds into a GitHub workflow. In particular:

  • a Jenkins build gets triggered by any PR or any update to any PR or when any PR are merged

  • the outcome of the Jenkins build outcome is displayed on GitHub

  • a Jenkins build failure disables the GitHub merge button



  • an existing repo

  • a Jenkins machine


  • one more job on Jenkins

  • GitHub repo linked

Create token on GitHub

  1. Log into you GitHub account, that must be an account with admin privileges to the repo

  2. Go to “Settings” of your GitHub account, then go to “Developer settings->Personal access tokens“

  3. Click “Generate new token“ and Select the following scopes:

    1. repo

      1. repo:status

      2. repos_deployment

      3. public_repo

    2. admin:repo_hook

      1. write:repo_hook

      2. read:repo_hook

  4. Give a name of the token in the “Note“ field and Click “Generate token“

  5. The token will show up under the “Personal access tokens“ page, click “copy” button to copy the token to somewhere temporal. When it’s set in the target application, remove delete the token from anywhere else.

Create webhook on GitHub

  1.  Log into your GitHub account, that must be an account with admin privileges to the repo

  2. In the “Settings” tab of the repo, click on “Webhooks”

  3. Click “Add webhook”, under “Webhooks / Manage webhook”

    1. Put <> (“github-webhook“ is a magic string identifying the GitHub plugin) in the Payload URL

    2. Select “Let me select individual events“ and check the “Pull Request”, “Push” and “Repositories” as the event to trigger the build

    3. Click “Update webhook” to create the webhook

  4. You should see the payload URL is the “Webhooks” list, with a green check mark.

Create Job on Jenkins

  1. install plugin

    1. Log into

    2. Go to “Manage Jenkins → Manage Plugins”, under Available tab, search for ”GitHub Branch Source”, mark the checkbox of the plugin

    3. search for ”SCM Filter Branch PR” and mark the checkbox of the plugin

    4. click “Install without restart” to install

    5. Go to and click “Yes” to restart Jenkins

  2. create new job

    1. Click “New Item” to create a job, give a name of the job, select “GitHub Organization” and then click “OK” to get in the job configure page

    2. In the “Projects” Tab, in the “GitHub Organization“ section, Click “Add” next to “Credentials“

      1. Select the option with the job name

      2. In “Kind“ text box, select “Username with password“

      3. In “Username“ text box, write down the GitHub account name

      4. In “Password“ text box, write down the token created in Create-token-on-GitHub

      5. Click “Add“ to return to the “configure“ page

      6. In the drop box of “Credentials“, select “[accoutname]/**********“

  3. In the “Owner“ text box, type down the GitHub Account/Organization name. This allows the Job to read the related branches/PR associated with the account/organization

  4. In the “Behaviors“ part, click the “Add“ button at bottom to add the following configurations:

    1. Repositories

      1. “Filter by name (with wildcards)”, using “Include“/”Exclude” to filter the repository you want the job to hook

    2. Within repository

      1. “Discover branches“, select “Strategy“ as “Exclude branches that are also filed as PRs“

      2. “Discover pull requests from forks“, select “Strategy“ as “Merging the pull request with current target“, select “Trust“ as “Everyone“

      3. “Filter by name including PRs destined for this branch (with wildcards)“, type down “master“ in “ Branch Include” text box

  5. In the “Project Recongnizers“ part, write down the Script path to the “Jenkinsfile“, which contains the Pipeline script that the Job should run

  6. In “Scan organization triggers“, uncheck the “Periodically if not otherwise run“

  7. In “Child Scan Triggers“, uncheck the “Periodically if not otherwise run“

  8. Click “Apply“ then “Save” to complete the settings.Create-token-on-GitHub

Create Jenkinsfile in Repository

The Github Organization job uses Pipeline as the build action to run.

The Pipeline script lives in the repository with name “jenkinsfile”. Following is an example what the Pipeline script looks like.


pipeline { agent { label 'windows && a102' } stages { stage('Test') { steps { bat 'pytest --junitxml=report.xml' } } } post { always { junit 'report.xml' } } }


  • repo:

  • Jenkins job:

  • GitHub Status images:

    • When Jenkins build passes, GitHub shows


    • When Jenkins build fails, GitHub shows