How to trigger a Jenkins build when a push is made to a private github repository

19,196

Solution 1

I had a similar problem, and after looking at the main Jenkins System Log I saw the following:

Feb 15, 2013 8:35:44 PM hudson.security.csrf.CrumbFilter doFilter
WARNING: No valid crumb was included in request for /github-webhook/.  Returning 403.

The solution is to switch off the CSRF protection - Manage Jenkins > Configure System > Prevent Cross Site Request Forgery exploits. The checkbox is just at the bottom of the first configuration section. After that it all seemed to work happily.

Solution 2

Create a logger with trace level logging for the com.cloudbees.jenkins category under your /log url (Manage Jenkins-> System logs).

Verify that there is a Webhook URL entry under the Service Hooks section of your repository administration screen.

Click test hook and you should see some log activity under your newly created logger.

Finally, check the GitHub Polling log action on the build which you have configured to be triggered by GitHub pushes.

A common mistake is testing commit hooks like this without having a change present.

The hook is only used to prompt a poll and won't perform a build unless changes are detected.

Share:
19,196

Related videos on Youtube

Kim Stacks
Author by

Kim Stacks

I build end-to-end workflow solutions to process data such as BOQ (Bill of Quantities) for businesses in telecomms, civil engineering, and construction.

Updated on June 04, 2022

Comments

  • Kim Stacks
    Kim Stacks almost 2 years

    My Jenkins Continuous Integration Server is on running on a Ubuntu host, configured as follows:

    • Jenkins v 1.463
    • github-api 1.23
    • Jenkins GIT plugin 1.1.18
    • GitHub plugin 1.2

    Polling SCM works. This is important to say because I want you to know my other jenkins related configuration is working well except this post build trigger nonsense.

    I want to configure Jenkins so that when changes are pushed to a development branch in a private github repository this will then trigger a build that incorporates the most recent changes.

    The repo is under my personal github account as owner. Let's call this owner

    I am including another github.com account as collaborator. Let's call this collaborator

    The reason I am doing this is because in case I am no longer involved in the project, somebody else can carry on with the maintenance.

    The SSH keys for the jenkins user in ubuntu are stored under collaborator

    I have consulted the following links:

    http://nepalonrails.tumblr.com/post/14217655627/set-up-jenkins-ci-on-ubuntu-for-painless-rails3-app-ci

    https://issues.jenkins-ci.org/browse/JENKINS-10391

    https://wiki.jenkins-ci.org/display/JENKINS/Github+Plugin

    http://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/

    https://wiki.jenkins-ci.org/display/JENKINS/Logging

    http://blog.cloudbees.com/2012/01/better-integration-between-jenkins-and.html

    None of it is not working. Some look a bit dated or even contradictory.

    I have added github.com to knownhosts for jenkins ubuntu user. I have added the github webhook.

    I have tried manual and auto github webhook setup in jenkins.

    Nothing works.

    I need a step by step guide on how to achieve this without polling github.

  • Kim Stacks
    Kim Stacks almost 12 years
    I followed your advice. i added to webhook url. nothing happened during when I pressed Test hook. I added to jenkins hook url and press Test hook. there is a payload sent on github.com website. When i check the logger, nothing happened. DO I need to switch off the SCM Polling when I run this test?
  • Kim Stacks
    Kim Stacks almost 12 years
    Can you please provide screenshots?
  • Giorgio
    Giorgio almost 11 years
    on jenkins on cloudbees.com the Prevent Cross Site Request Forgery Explouts does not appear! Is there another way to disable CSRF. For example using Jenkins CLI?
  • michele b
    michele b almost 10 years
    The setting moved to Manage Jenkins > Configure Global Security > Prevent Cross Site Request Forgery exploits, at the very bottom of the page. Using Jenkins version 1.572
  • Marco
    Marco about 9 years
    In case it can help anyone, this solution also works for the same error, but with /bitbucket-hook