Search code examples
githubjenkinsjenkins-pipelinegithub-webhook

Jenkins github webhook integration not working?


Using Jenkins v2.401.2

Am using Github jenkins plugin (comes with Jenkins) to manually configure a webhook and have it run on every action thus triggering my Jenkins job.

Getting: POST /github-webhook/ 200 OK when an action is triggered on Github, however the Jenkins pipeline doesn't trigger.

On Jenkins side:

  • created a pipeline project
  • ticked the GitHub hook trigger for GITScm polling
  • ticked the Github project and specified the URL to my project
  • created a token for my user and using it as a secret on Github (it's not needed)

Still don't see the Jenkins pipeline being triggered. Am setting the webhook via Manual Mode

enter image description here

EDIT

This triggers for freestyle project when selecting the appropriate checkboxes but does not work for pipeline project.

enter image description here


Solution

  • I use multibranch pipeline and I don't have this problem, but if I change to pipeline I have the same behaviour.

    After some tries, and check the plugin code and this issue seems that to solve the issue you have to follow these steps (I suppose that webhooks part is well configured):

    1. Use the same name on the pipeline, that the name used in the github repository. In my case this github repository: https://github.com/ConsorciAOC-PRJ/qa_payload-jenkins.git/ and the job name on jenkins qa_payload-jenkins.

    enter image description here

    1. As explained in the issue above, you have to register the push trigger and the job's repository, adding the following code in your pipeline, in my case:
    properties([pipelineTriggers([githubPush()])])
    
    node {
        git credentialsId: 'b8d10285-xxxx-xxxx-xxxx-xxxxx',
            url: 'https://github.com/ConsorciAOC-PRJ/qa_payload-jenkins.git', branch: 'main'
    }
    
    1. You have to run once the pipeline in order that the register takes effect, then each push start triggering the job.

    NOTE: I tested using credentialsId but you can use the autenticathion mechanism you prefer. Until git is not correct authenticated the push triggered and the job will not be registered.