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

Webhook registration fails for private Github repositories

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • github-plugin
    • 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

      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)
      
      

          [JENKINS-40359] Webhook registration fails for private Github repositories

          Justin Silver created issue -

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

          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?

          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.

          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.

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

          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]
          Kanstantsin Shautsou made changes -
          Assignee Original: Kirill Merkushev [ lanwen ] New: Kanstantsin Shautsou [ integer ]

          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?

          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?

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

          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.
          Justin Silver made changes -
          Attachment New: Screen Shot 2016-12-12 at 5.15.35 PM.png [ 35147 ]

          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
          

          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

          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.

          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.

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

              Created:
              Updated:
              Resolved: