Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-40359

Webhook registration fails for private Github repositories

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Not A Defect
    • Component/s: github-plugin
    • Environment:
      CentOS 7
      Jenkins 2.35
      GitHub API Plugin 1.80
      GitHub Authentication plugin 0.25
      GitHub Branch Source Plugin 1.5
      GitHub plugin 1.24.0
    • Similar Issues:

      Description

      Registering webhooks for private repositories fails, however it is successful for public repositories using the same access token for my account. I am able to clone the repository in the job, so I believe that my user access is properly configured, and all of the repositories are under my account, so I should have admin access. The access token does contain admin:repo_hook, and seems to be configured correctly based on the registration succeeding for the public repositories.

      I enabled logging based on the recommendation of the Github plugin and see the following:

      Dec 10, 2016 10:31:51 PM FINE com.cloudbees.jenkins.GitHubWebHook$1 apply
      Calling registerHooks() for PUBLIC_PROJECT
      
      Dec 10, 2016 10:31:51 PM FINE com.cloudbees.jenkins.GitHubWebHook$1 apply
      Calling registerHooks() for PRIVATE_PROJECT
      
      Dec 10, 2016 10:31:51 PM INFO org.jenkinsci.plugins.github.webhook.WebhookManager$1 run
      GitHub webhooks activated for job email-templates-mock with [GitHubRepositoryName[host=github.com,username=doublesharp,repository=PUBLIC_PROJECT]] (events: [PUSH, REPOSITORY])
      
      Dec 10, 2016 10:31:51 PM INFO org.jenkinsci.plugins.github.webhook.WebhookManager$1 run
      GitHub webhooks activated for job PRIVATE_PROJECT with [GitHubRepositoryName[host=github.com,username=doublesharp,repository=PRIVATE_PROJECT]] (events: [PUSH, REPOSITORY])
      
      Dec 10, 2016 10:31:51 PM WARNING org.jenkinsci.plugins.github.webhook.WebhookManager$2 applyNullSafe
      Failed to add GitHub webhook for GitHubRepositoryName[host=github.com,username=doublesharp,repository=PRIVATE_PROJECT]
      java.lang.NullPointerException: There is no credentials with admin access to manage hooks on GitHubRepositoryName[host=github.com,username=doublesharp,repository=PRIVATE_PROJECT]
      	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:231)
      	at org.jenkinsci.plugins.github.webhook.WebhookManager$2.applyNullSafe(WebhookManager.java:156)
      	at org.jenkinsci.plugins.github.webhook.WebhookManager$2.applyNullSafe(WebhookManager.java:152)
      	at org.jenkinsci.plugins.github.util.misc.NullSafeFunction.apply(NullSafeFunction.java:18)
      	at com.google.common.collect.Iterators$8.next(Iterators.java:812)
      	at com.google.common.collect.Iterators$7.computeNext(Iterators.java:648)
      	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
      	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
      	at com.google.common.collect.Iterators$7.computeNext(Iterators.java:647)
      	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
      	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
      	at com.google.common.collect.Lists.newArrayList(Lists.java:138)
      	at com.google.common.collect.Lists.newArrayList(Lists.java:119)
      	at org.jenkinsci.plugins.github.util.FluentIterableWrapper.toList(FluentIterableWrapper.java:137)
      	at org.jenkinsci.plugins.github.webhook.WebhookManager$1.run(WebhookManager.java:104)
      	at hudson.util.SequentialExecutionQueue$QueueEntry.run(SequentialExecutionQueue.java:119)
      	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      	at java.lang.Thread.run(Thread.java:745)
      
      

        Attachments

          Activity

          Hide
          integer Kanstantsin Shautsou added a comment -

          How much github servers do you have in global settings?
          Have you ensured that global user accepted invite to repository?

          Show
          integer Kanstantsin Shautsou added a comment - How much github servers do you have in global settings? Have you ensured that global user accepted invite to repository?
          Hide
          doublesharp Justin Silver added a comment -

          Just one Github server - "https://api.github.com", using a Personal Access Token for my user.

          Which global user are you referring to? My configuration is only using my personal Github user.

          Show
          doublesharp Justin Silver added a comment - Just one Github server - "https://api.github.com", using a Personal Access Token for my user. Which global user are you referring to? My configuration is only using my personal Github user.
          Hide
          integer Kanstantsin Shautsou added a comment -

          java.lang.NullPointerException: There is no credentials with admin access to manage hooks on GitHubRepositoryName[host=github.com,username=doublesharp,repository=PRIVATE_PROJECT]

          Show
          integer Kanstantsin Shautsou added a comment - java.lang.NullPointerException: There is no credentials with admin access to manage hooks on GitHubRepositoryName [host=github.com,username=doublesharp,repository=PRIVATE_PROJECT]
          Hide
          doublesharp Justin Silver added a comment - - edited

          "doublesharp" is my Github username, and all of the repositories in my Jenkins install belong to that account. I am able to create the webhooks from Jenkins for the public repositories (like https://github.com/doublesharp/lru-cache-for-clusters-as-promised), however it does not create the webhooks for my private repositories. I am able to build the private projects manually, or from manually created webhooks, so the "doublesharp" user is able to clone the private repository, which I assumed meant that it was configured correctly within the job. Does this user need to be configured elsewhere to access the API?

          Show
          doublesharp Justin Silver added a comment - - edited "doublesharp" is my Github username, and all of the repositories in my Jenkins install belong to that account. I am able to create the webhooks from Jenkins for the public repositories (like https://github.com/doublesharp/lru-cache-for-clusters-as-promised ), however it does not create the webhooks for my private repositories. I am able to build the private projects manually, or from manually created webhooks, so the "doublesharp" user is able to clone the private repository, which I assumed meant that it was configured correctly within the job. Does this user need to be configured elsewhere to access the API?
          Hide
          integer Kanstantsin Shautsou added a comment -

          What scopes do you have for this user token that used in global configuration? Does it have private_repo? Please provide screenshot.

          Show
          integer Kanstantsin Shautsou added a comment - What scopes do you have for this user token that used in global configuration? Does it have private_repo? Please provide screenshot.
          Hide
          doublesharp Justin Silver added a comment -

          I don't have "private_repo" available as a scope, but per the UI the "repo" scope should allow full access to private repositories.

          Screenshot with selected scopes:

          Looking at the full system log the stracktrace that I posted earlier is preceded by this error:

          Failed to obtain repository com.cloudbees.jenkins.GitHubRepositoryName$1@603ff301
          java.io.FileNotFoundException: {"message":"Not Found","documentation_url":"https://developer.github.com/v3"}
          	at org.kohsuke.github.Requester.handleApiError(Requester.java:592)
          	at org.kohsuke.github.Requester._to(Requester.java:272)
          	at org.kohsuke.github.Requester.to(Requester.java:213)
          	at org.kohsuke.github.GitHub.getRepository(GitHub.java:369)
          	at com.cloudbees.jenkins.GitHubRepositoryName$1.applyNullSafe(GitHubRepositoryName.java:218)
          	at com.cloudbees.jenkins.GitHubRepositoryName$1.applyNullSafe(GitHubRepositoryName.java:214)
          	at org.jenkinsci.plugins.github.util.misc.NullSafeFunction.apply(NullSafeFunction.java:18)
          	at com.google.common.collect.Iterators$8.next(Iterators.java:812)
          	at com.google.common.collect.Iterators$7.computeNext(Iterators.java:648)
          	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
          	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
          	at com.google.common.collect.Iterators$7.computeNext(Iterators.java:647)
          	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
          	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
          	at com.google.common.collect.Iterators.tryFind(Iterators.java:757)
          	at com.google.common.collect.Iterables.tryFind(Iterables.java:671)
          	at org.jenkinsci.plugins.github.util.FluentIterableWrapper.firstMatch(FluentIterableWrapper.java:126)
          	at org.jenkinsci.plugins.github.webhook.WebhookManager$2.applyNullSafe(WebhookManager.java:180)
          	at org.jenkinsci.plugins.github.webhook.WebhookManager$2.applyNullSafe(WebhookManager.java:175)
          	at org.jenkinsci.plugins.github.util.misc.NullSafeFunction.apply(NullSafeFunction.java:18)
          	at com.google.common.collect.Iterators$8.next(Iterators.java:812)
          	at com.google.common.collect.Iterators$7.computeNext(Iterators.java:648)
          	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
          	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
          	at com.google.common.collect.Iterators$7.computeNext(Iterators.java:647)
          	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
          	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
          	at com.google.common.collect.Lists.newArrayList(Lists.java:138)
          	at com.google.common.collect.Lists.newArrayList(Lists.java:119)
          	at org.jenkinsci.plugins.github.util.FluentIterableWrapper.toList(FluentIterableWrapper.java:147)
          	at org.jenkinsci.plugins.github.webhook.WebhookManager$1.run(WebhookManager.java:127)
          	at hudson.util.SequentialExecutionQueue$QueueEntry.run(SequentialExecutionQueue.java:119)
          	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
          	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
          	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
          	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
          	at java.lang.Thread.run(Thread.java:745)
          Caused by: java.io.FileNotFoundException: https://api.github.com/repos/doublesharp/PRIVATE_REPOSITORY
          	at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:243)
          	at com.squareup.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
          	at com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25)
          	at org.kohsuke.github.Requester.parse(Requester.java:524)
          	at org.kohsuke.github.Requester._to(Requester.java:251)
          	... 36 more
          
          Show
          doublesharp Justin Silver added a comment - I don't have "private_repo" available as a scope, but per the UI the "repo" scope should allow full access to private repositories. Screenshot with selected scopes: Looking at the full system log the stracktrace that I posted earlier is preceded by this error: Failed to obtain repository com.cloudbees.jenkins.GitHubRepositoryName$1@603ff301 java.io.FileNotFoundException: {"message":"Not Found","documentation_url":"https://developer.github.com/v3"} at org.kohsuke.github.Requester.handleApiError(Requester.java:592) at org.kohsuke.github.Requester._to(Requester.java:272) at org.kohsuke.github.Requester.to(Requester.java:213) at org.kohsuke.github.GitHub.getRepository(GitHub.java:369) at com.cloudbees.jenkins.GitHubRepositoryName$1.applyNullSafe(GitHubRepositoryName.java:218) at com.cloudbees.jenkins.GitHubRepositoryName$1.applyNullSafe(GitHubRepositoryName.java:214) at org.jenkinsci.plugins.github.util.misc.NullSafeFunction.apply(NullSafeFunction.java:18) at com.google.common.collect.Iterators$8.next(Iterators.java:812) at com.google.common.collect.Iterators$7.computeNext(Iterators.java:648) at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143) at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138) at com.google.common.collect.Iterators$7.computeNext(Iterators.java:647) at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143) at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138) at com.google.common.collect.Iterators.tryFind(Iterators.java:757) at com.google.common.collect.Iterables.tryFind(Iterables.java:671) at org.jenkinsci.plugins.github.util.FluentIterableWrapper.firstMatch(FluentIterableWrapper.java:126) at org.jenkinsci.plugins.github.webhook.WebhookManager$2.applyNullSafe(WebhookManager.java:180) at org.jenkinsci.plugins.github.webhook.WebhookManager$2.applyNullSafe(WebhookManager.java:175) at org.jenkinsci.plugins.github.util.misc.NullSafeFunction.apply(NullSafeFunction.java:18) at com.google.common.collect.Iterators$8.next(Iterators.java:812) at com.google.common.collect.Iterators$7.computeNext(Iterators.java:648) at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143) at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138) at com.google.common.collect.Iterators$7.computeNext(Iterators.java:647) at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143) at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138) at com.google.common.collect.Lists.newArrayList(Lists.java:138) at com.google.common.collect.Lists.newArrayList(Lists.java:119) at org.jenkinsci.plugins.github.util.FluentIterableWrapper.toList(FluentIterableWrapper.java:147) at org.jenkinsci.plugins.github.webhook.WebhookManager$1.run(WebhookManager.java:127) at hudson.util.SequentialExecutionQueue$QueueEntry.run(SequentialExecutionQueue.java:119) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.io.FileNotFoundException: https://api.github.com/repos/doublesharp/PRIVATE_REPOSITORY at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:243) at com.squareup.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210) at com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25) at org.kohsuke.github.Requester.parse(Requester.java:524) at org.kohsuke.github.Requester._to(Requester.java:251) ... 36 more
          Hide
          doublesharp Justin Silver added a comment -

          I forgot to mentioned that I am replacing the real private repository name with "PRIVATE_REPOSITORY" in the error logs.

          Show
          doublesharp Justin Silver added a comment - I forgot to mentioned that I am replacing the real private repository name with "PRIVATE_REPOSITORY" in the error logs.
          Hide
          integer Kanstantsin Shautsou added a comment -

          Is it org or user?

          Show
          integer Kanstantsin Shautsou added a comment - Is it org or user?
          Hide
          doublesharp Justin Silver added a comment -

          "doublesharp" is a user account.

          I'm still trying to debug on my end, and now I'm seeing strange behavior. I have 7 total jobs, with 4 public and 3 private. When I submitted this issue the 4 public repositories worked and all 3 private repositories were failing, however now only 1 private is failing and the others are successful. I manually deleted the webhook and verified that it was recreated by Jenkins when I saved the project configuration.

          I don't see any meaningful differences between the configurations, so I wonder if maybe the issue is actually with Github?

          Show
          doublesharp Justin Silver added a comment - "doublesharp" is a user account. I'm still trying to debug on my end, and now I'm seeing strange behavior. I have 7 total jobs, with 4 public and 3 private. When I submitted this issue the 4 public repositories worked and all 3 private repositories were failing, however now only 1 private is failing and the others are successful. I manually deleted the webhook and verified that it was recreated by Jenkins when I saved the project configuration. I don't see any meaningful differences between the configurations, so I wonder if maybe the issue is actually with Github?
          Hide
          doublesharp Justin Silver added a comment -

          I created a new private repository with only a README.md and copied the failing job only replacing the git URL with the new project name and it successfully created the webhooks. I also copied the failing job and just ran it without success. This seems to me to point to an error on Github's side, not Jenkins.

          Show
          doublesharp Justin Silver added a comment - I created a new private repository with only a README.md and copied the failing job only replacing the git URL with the new project name and it successfully created the webhooks. I also copied the failing job and just ran it without success. This seems to me to point to an error on Github's side, not Jenkins.
          Hide
          doublesharp Justin Silver added a comment -

          I renamed the repository in Github "project" to "project2" and then changed the URL in the job configuration, and when I saved the webhook was created on Github. I then deleted the webhook, renamed the project back to the original name, removed the 2 from the Jenkins config, and once it again it was able to create the webhooks when I saved.

          It seems that something was in fact messed up with my project on Github and renaming it seems to have fixed it....

          Show
          doublesharp Justin Silver added a comment - I renamed the repository in Github "project" to "project2" and then changed the URL in the job configuration, and when I saved the webhook was created on Github. I then deleted the webhook, renamed the project back to the original name, removed the 2 from the Jenkins config, and once it again it was able to create the webhooks when I saved. It seems that something was in fact messed up with my project on Github and renaming it seems to have fixed it....
          Hide
          doublesharp Justin Silver added a comment - - edited

          Authentication error seems to be with Github even with proper Jenkins configuration. Some projects resolved the issue on their own, the remaining project was corrected by renaming on Github to an arbitrary value and then back to the original name.

          Show
          doublesharp Justin Silver added a comment - - edited Authentication error seems to be with Github even with proper Jenkins configuration. Some projects resolved the issue on their own, the remaining project was corrected by renaming on Github to an arbitrary value and then back to the original name.

            People

            Assignee:
            integer Kanstantsin Shautsou
            Reporter:
            doublesharp Justin Silver
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: