Github-webhook not triggering a job because pipeline doesn’t have a matching repository

Jenkins

I have setup a github webhook and also setup logs on the github plugin in jenkins. Jenkins seems to receive correct payload on the webhook. However the log says that github webhook considered poking my job and then after that it skips because it didn't find a matching repository

I am on jenkins 2.1 and recently migrated to 2.5

Received POST for https://github.com/<org_name>/<repo_name>
May 20, 2016 3:17:49 PM FINE  org.jenkinsci.plugins.github.webhook.subscriber.DefaultPushGHEventSubscriber$1 run
Considering to poke echo_pipeline
May 20, 2016 3:17:49 PM FINE org.jenkinsci.plugins.github.webhook.subscriber.DefaultPushGHEventSubscriber$1 run
Skipped echo_pipeline because it doesn't have a matching repository.

I have added this repository in the configuration of the job for pipeline and I am also cloning this repository in the pipeline. Where else do I need to configure repository so that the webhook considers this and doesn't skip it

Best Answer

I know this is an old thread but for the benefit of those who end up here:

1) Your job has to have run at least once manually before the hook will work

2) The repo pushing to Jenkins, the GitHub project url in the project configuration, and the repo(s) in your pipeline Job have to line up.

3) You need a log recorder in Jenkins to see what's being sent by GitHub: https://support.cloudbees.com/hc/en-us/articles/204880580-How-do-I-create-a-logger-in-Jenkins-for-troubleshooting-and-diagnostic-information-

I dug into the Jenkins code (https://github.com/jenkinsci/github-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventSubscriber.java#L88-L107) to figure out what wasn't matching up. You can see what it's expecting in the pipeline by going to your Jenkins instance script console (/script) and executing this:

import com.cloudbees.jenkins.GitHubRepositoryNameContributor;

for (Item job : Jenkins.getInstance().getAllItems(Item.class)) {
  print(GitHubRepositoryNameContributor.parseAssociatedNames(job))
}

That will loop through all your jobs and output the values for the repos that it's checking against.