Skip to content

Instantly share code, notes, and snippets.

@ghsatpute
Last active February 5, 2021 16:24
Show Gist options
  • Save ghsatpute/53ee8c5b4c6cf3103466ad17d889e139 to your computer and use it in GitHub Desktop.
Save ghsatpute/53ee8c5b4c6cf3103466ad17d889e139 to your computer and use it in GitHub Desktop.
Create Github PR Jobs on Jenkins

Steps to configure PR jobs on Jenkins This job will run every time someone creates a pull request on your Github repository

  1. On Jenkins 
    1. Install Jenkins PR Plugin https://plugins.jenkins.io/ghprb/
    2. Create a freestyle project 
    3. Add Github project link
    4. In Source code management > branch specifier add ${ghprbActualCommit}
    5. Click on advance and add Refspec as "+refs/pull/:refs/remotes/origin/pr/" (because we want to run only for PRs)
    6. In Triggers, select "Github Pull Request Builder"
    7. Check "Use github hooks for build triggering"
    8. Check "Build every pull request automatically without asking (Dangerous!)."
    9. Whitelist target branch, in our case i.e. develop
    10. In build step, add execute shell and write your code which is supposed to be executed. Like running test, posting results etc. 
    11. Click on "Apply" and then "Save"
  2. Configurations on GitHub site 
    1. Goto repository > settings > Hooks

    2. Click on "Add webhook"

    3. In URL type <Jenkins Server URL\>/ghprbhook/

      If you get this error,

      HTTP ERROR 403 No valid crumb was included in the request
      

      You probably forget the slash at the end)

    4. Selct Content Type as "application/json"

    5. Under "Which events would you like to trigger this webhook?", select "Let me select individual events."

    6. Select "Pushes" and "Pull requests" from available options Select checkbox in front of "Active" Click on "Create Webhook"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment