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

Github multibranch: GitHub Webhook is not created right after saving the job

    Details

    • Sprint:
      Pipeline - December
    • Similar Issues:

      Description

      I am observing the following behavior:

      1.- Fresh installation, installing latest version of Pipeline, GitHub plugin and GitHub Branch Source Plugin

      2.- Manage Jenkins > Configuring GitHub plugin: Credentials of an Owner of a Organization which hosts a Repo X

      3.- New Pipeline Multibranch Item pointing to Repo X, after saving the job the webhook in GitHub is not automatically generated (vs. GitHub Organization Folder item which is done)

      4.- Manage Jenkins > GitHub plugin > Advanced > Re-register hooks for all jobs > webhook in GitHub is finally generated
       
      What I am reporting: I'd expect the webhook in GitHub is automatically generated right after the saving the Pipeline Multibranch Branch but it does not it until I click on Re-register hooks for all jobs (GitHub plugin)

        Attachments

          Issue Links

            Activity

            Hide
            shamil Alex Simenduev added a comment - - edited

            I'm experiencing exactly same issue. I'm adding jobs via Blueocean UI which creates "Pipeline Multibranch" jobs. And I don't see webhooks configured, even after initial manual build.

            Once I go to "Manage Jenkins > Configure System > GitHub plugin > Advanced > Re-register hooks for all jobs"  Webhooks get created.

            How this can  be solved? What I'm doing wrong?

             

             

            Show
            shamil Alex Simenduev added a comment - - edited I'm experiencing exactly same issue. I'm adding jobs via Blueocean UI which creates " Pipeline Multibranch " jobs. And I don't see webhooks configured, even after initial manual build. Once I go to " Manage Jenkins > Configure System > GitHub plugin > Advanced > Re-register hooks for all jobs "  Webhooks get created. How this can  be solved? What I'm doing wrong?    
            Hide
            michaelneale Michael Neale added a comment -

            Alex Simenduev this is a bug somehow (a regression). 

            Show
            michaelneale Michael Neale added a comment - Alex Simenduev this is a bug somehow (a regression). 
            Hide
            rsandell rsandell added a comment -

            After a lot of debugging, It seems like the webhooks aren't registered until a branch is built once because the existing GitHubRepositoryNameContributor implementations needs some information attached during the build to determine what repo to add the webhook to.
            There is no specific GitHubRepositoryNameContributor implemented for GitHub branch source that can extract that information ahead of the build.

            Show
            rsandell rsandell added a comment - After a lot of debugging, It seems like the webhooks aren't registered until a branch is built once because the existing GitHubRepositoryNameContributor implementations needs some information attached during the build to determine what repo to add the webhook to. There is no specific GitHubRepositoryNameContributor implemented for GitHub branch source that can extract that information ahead of the build.
            Hide
            stevenfoster Steven Foster added a comment -

            That's what I found here https://issues.jenkins-ci.org/browse/JENKINS-46366?focusedCommentId=318622&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-318622

            Looking back at the workaround I made (it wasn't clear to me if it was the right approach and was getting mixed signals at the time about if there was a bug at all) I also needed an ItemListener to handle some webhook registration and deregistration cases. Probably better fixed in a different way.

            Show
            stevenfoster Steven Foster added a comment - That's what I found here https://issues.jenkins-ci.org/browse/JENKINS-46366?focusedCommentId=318622&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-318622 Looking back at the workaround I made (it wasn't clear to me if it was the right approach and was getting mixed signals at the time about if there was a bug at all) I also needed an ItemListener to handle some webhook registration and deregistration cases. Probably better fixed in a different way.
            Hide
            michaelneale Michael Neale added a comment -

            Still confused how this ever worked: surely an older version of GHBS worked out of the box without requiring a build first (seems a chicken and egg problem - it needs webhooks to trigger a build, although should there be a first time build and THEN try to setup the webhooks not up front?)

            Show
            michaelneale Michael Neale added a comment - Still confused how this ever worked: surely an older version of GHBS worked out of the box without requiring a build first (seems a chicken and egg problem - it needs webhooks to trigger a build, although should there be a first time build and THEN try to setup the webhooks not up front?)
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: rsandell
            Path:
            pom.xml
            src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceRepositoryNameContributor.java
            http://jenkins-ci.org/commit/github-branch-source-plugin/9213e3b0d1b12493e5d319fb4f3cb0f7be05edac
            Log:
            JENKINS-48035 Add a GitHubRepositoryNameContributor that recognises multi branch

            The existing name contributors could only find the repo name if a build
            of a branch had been made and added git build data to the job.
            Since branches are discovered and built after GitHubSCMSource.afterSaved is called
            there was no repo names recognised to add webhooks to.

            This only solves the case when a single multi branch project is created.
            Because when an org folder creates the multi branch jobs it does not call
            afterSaved on the children. So that needs to be fixed someplace else.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: rsandell Path: pom.xml src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceRepositoryNameContributor.java http://jenkins-ci.org/commit/github-branch-source-plugin/9213e3b0d1b12493e5d319fb4f3cb0f7be05edac Log: JENKINS-48035 Add a GitHubRepositoryNameContributor that recognises multi branch The existing name contributors could only find the repo name if a build of a branch had been made and added git build data to the job. Since branches are discovered and built after GitHubSCMSource.afterSaved is called there was no repo names recognised to add webhooks to. This only solves the case when a single multi branch project is created. Because when an org folder creates the multi branch jobs it does not call afterSaved on the children. So that needs to be fixed someplace else.
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: rsandell
            Path:
            pom.xml
            src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceRepositoryNameContributor.java
            http://jenkins-ci.org/commit/github-branch-source-plugin/93cc3f46474d74a9b7defa7c43ab3c1a59c87a04
            Log:
            JENKINS-48035 Revert branch-api back to test scope and use SCMSourceOwner

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: rsandell Path: pom.xml src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceRepositoryNameContributor.java http://jenkins-ci.org/commit/github-branch-source-plugin/93cc3f46474d74a9b7defa7c43ab3c1a59c87a04 Log: JENKINS-48035 Revert branch-api back to test scope and use SCMSourceOwner
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: rsandell
            Path:
            src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceTest.java
            http://jenkins-ci.org/commit/github-branch-source-plugin/945bd9842f98446123c4156fcf23962eabbc3b11
            Log:
            JENKINS-48035 Add a test

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: rsandell Path: src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceTest.java http://jenkins-ci.org/commit/github-branch-source-plugin/945bd9842f98446123c4156fcf23962eabbc3b11 Log: JENKINS-48035 Add a test
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: rsandell
            Path:
            src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceRepositoryNameContributor.java
            http://jenkins-ci.org/commit/github-branch-source-plugin/361e6d15eb71466e67081333bdfd7ab0da08b082
            Log:
            JENKINS-48035 And the license header

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: rsandell Path: src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceRepositoryNameContributor.java http://jenkins-ci.org/commit/github-branch-source-plugin/361e6d15eb71466e67081333bdfd7ab0da08b082 Log: JENKINS-48035 And the license header
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: rsandell
            Path:
            src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceTest.java
            http://jenkins-ci.org/commit/github-branch-source-plugin/0203fb201fc886ac826c96386f88b3d7775ab8f1
            Log:
            JENKINS-48035 negative tests

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: rsandell Path: src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceTest.java http://jenkins-ci.org/commit/github-branch-source-plugin/0203fb201fc886ac826c96386f88b3d7775ab8f1 Log: JENKINS-48035 negative tests
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: rsandell
            Path:
            src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceRepositoryNameContributor.java
            http://jenkins-ci.org/commit/github-branch-source-plugin/99d72b0ae93952b5fb941d6f71f63d45abf7cab2
            Log:
            JENKINS-48035 javadoc

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: rsandell Path: src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceRepositoryNameContributor.java http://jenkins-ci.org/commit/github-branch-source-plugin/99d72b0ae93952b5fb941d6f71f63d45abf7cab2 Log: JENKINS-48035 javadoc
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Stephen Connolly
            Path:
            pom.xml
            src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceRepositoryNameContributor.java
            src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceTest.java
            http://jenkins-ci.org/commit/github-branch-source-plugin/3bf8714bffc7467d81099542e3e421203a4695a0
            Log:
            Merge pull request #170 from rsandell/JENKINS-48035

            JENKINS-48035 Add a GitHubRepositoryNameContributor that recognises…

            Compare: https://github.com/jenkinsci/github-branch-source-plugin/compare/267e41c59581...3bf8714bffc7

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Stephen Connolly Path: pom.xml src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceRepositoryNameContributor.java src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceTest.java http://jenkins-ci.org/commit/github-branch-source-plugin/3bf8714bffc7467d81099542e3e421203a4695a0 Log: Merge pull request #170 from rsandell/ JENKINS-48035 JENKINS-48035 Add a GitHubRepositoryNameContributor that recognises… Compare: https://github.com/jenkinsci/github-branch-source-plugin/compare/267e41c59581...3bf8714bffc7
            Hide
            stephenconnolly Stephen Connolly added a comment -

            claimed resolved in 2.3.2

            Show
            stephenconnolly Stephen Connolly added a comment - claimed resolved in 2.3.2
            Hide
            michaelneale Michael Neale added a comment -

            Just reopening to make sure we do org folders as well 

            Show
            michaelneale Michael Neale added a comment - Just reopening to make sure we do org folders as well 
            Hide
            michaelneale Michael Neale added a comment -

            Stephen Connolly can this then be closed? 

            Show
            michaelneale Michael Neale added a comment - Stephen Connolly can this then be closed? 
            Hide
            carlosrodlop Carlos Rodríguez López added a comment - - edited

            rsandell Stephen Connolly I am reopening this ticket again because the same reported issue seems to be back running (Regression?)

            Environment

            Jenkins LTS 2.164.2
             * github:1.29.4 'GitHub plugin'
             * github-api:1.95 'GitHub API Plugin'
             * github-branch-source:2.5.0 *(update available)* 'GitHub Branch Source Plugin'
            

            Observations

            What we see on Jenkins logs
            May 16, 2019 3:12:38 PM org.jenkinsci.plugins.github.webhook.WebhookManager$2 applyNullSafe
            WARNING: Failed to add GitHub webhook for GitHubRepositoryName[host=github.com,username=mock-carlosrodlop-org,repository=my-hw-maven-app]
            java.lang.NullPointerException: There are no credentials with admin access to manage hooks on GitHubRepositoryName[host=github.com,username=mock-carlosrodlop-org,repository=my-hw-maven-app]
            

            But it is not right... I am using this repo https://github.com/mock-carlosrodlop-org/my-hw-maven-app with user:carlosrodlop and pass:APIToken and as you can tell from the following images carlosrodlop is an admin

            Custom dedicated loggers as explained in this guide: GitHub-Webhook-Troubleshooting are not providing any useful hint just
            May 16, 2019 4:05:50 PM FINE com.cloudbees.jenkins.GitHubWebHook$1 apply
            Calling registerHooks() for multibranch-example-job
            May 16, 2019 4:05:51 PM FINE com.cloudbees.jenkins.GitHubWebHook$1 apply
            Calling registerHooks() for multibranch-example-job
            
            Manage Jenkins > GitHub plugin > Advanced > Re-register hooks for all jobs > webhook in GitHub is NOT generated either. Independently if I enabled or disable Manage hooks options the output is the same: Works only when Jenkins manages hooks (one or more creds specified)
            Show
            carlosrodlop Carlos Rodríguez López added a comment - - edited rsandell Stephen Connolly I am reopening this ticket again because the same reported issue seems to be back running (Regression?) Environment Jenkins LTS 2.164.2 * github:1.29.4 'GitHub plugin' * github-api:1.95 'GitHub API Plugin' * github-branch-source:2.5.0 *(update available)* 'GitHub Branch Source Plugin' Observations What we see on Jenkins logs May 16, 2019 3:12:38 PM org.jenkinsci.plugins.github.webhook.WebhookManager$2 applyNullSafe WARNING: Failed to add GitHub webhook for GitHubRepositoryName[host=github.com,username=mock-carlosrodlop-org,repository=my-hw-maven-app] java.lang.NullPointerException: There are no credentials with admin access to manage hooks on GitHubRepositoryName[host=github.com,username=mock-carlosrodlop-org,repository=my-hw-maven-app] But it is not right... I am using this repo https://github.com/mock-carlosrodlop-org/my-hw-maven-app with user:carlosrodlop and pass:APIToken and as you can tell from the following images carlosrodlop is an admin Custom dedicated loggers as explained in this guide: GitHub-Webhook-Troubleshooting are not providing any useful hint just May 16, 2019 4:05:50 PM FINE com.cloudbees.jenkins.GitHubWebHook$1 apply Calling registerHooks() for multibranch-example-job May 16, 2019 4:05:51 PM FINE com.cloudbees.jenkins.GitHubWebHook$1 apply Calling registerHooks() for multibranch-example-job Manage Jenkins > GitHub plugin > Advanced > Re-register hooks for all jobs > webhook in GitHub is NOT generated either. Independently if I enabled or disable Manage hooks options the output is the same: Works only when Jenkins manages hooks (one or more creds specified)
            Hide
            carlosrodlop Carlos Rodríguez López added a comment -

            It is working fine after deep testing

            Show
            carlosrodlop Carlos Rodríguez López added a comment - It is working fine after deep testing
            Hide
            dlakatos847 David Lakatos added a comment - - edited

            Carlos Rodríguez López I experienced the same issue you did. What do you mean "It is working fine after deep testing"? How did your problem disappear?

            While my OAuth token used by Jenkins has the admin:repo_hook permission on Github, Jenkins throws this exception for all of my managed repositories:

            Jul 06, 2019 10:34:16 AM WARNING org.jenkinsci.plugins.github.webhook.WebhookManager$2 applyNullSafe
            Failed to add GitHub webhook for GitHubRepositoryName[host=github.com,username=*****,repository=*****]
            java.lang.NullPointerException: There are no credentials with admin access to manage hooks on GitHubRepositoryName[host=github.com,username=*****,repository=*****]
            at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:231)
            at org.jenkinsci.plugins.github.webhook.WebhookManager$2.applyNullSafe(WebhookManager.java:179)
            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 jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
            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:1149)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
            at java.lang.Thread.run(Thread.java:748)

            Show
            dlakatos847 David Lakatos added a comment - - edited Carlos Rodríguez López I experienced the same issue you did. What do you mean "It is working fine after deep testing"? How did your problem disappear? While my OAuth token used by Jenkins has the admin:repo_hook permission on Github, Jenkins throws this exception for all of my managed repositories: Jul 06, 2019 10:34:16 AM WARNING org.jenkinsci.plugins.github.webhook.WebhookManager$2 applyNullSafe Failed to add GitHub webhook for GitHubRepositoryName [host=github.com,username=*****,repository=*****] java.lang.NullPointerException: There are no credentials with admin access to manage hooks on GitHubRepositoryName [host=github.com,username=*****,repository=*****] at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:231) at org.jenkinsci.plugins.github.webhook.WebhookManager$2.applyNullSafe(WebhookManager.java:179) 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 jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59) 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:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
            Hide
            dlakatos847 David Lakatos added a comment -

            FYI I fixed my issue by regenerating my OAuth access token. It may have been misconfigured in my Jenkins' credentials...

            Show
            dlakatos847 David Lakatos added a comment - FYI I fixed my issue by regenerating my OAuth access token. It may have been misconfigured in my Jenkins' credentials...
            Hide
            carlosrodlop Carlos Rodríguez López added a comment -

            Hi David Lakatos,

            I forgot to configure correctly the Git Plugin see https://support.cloudbees.com/hc/en-us/articles/224543927-GitHub-Integration-Webhooks

            Regards,

            Show
            carlosrodlop Carlos Rodríguez López added a comment - Hi David Lakatos , I forgot to configure correctly the Git Plugin see https://support.cloudbees.com/hc/en-us/articles/224543927-GitHub-Integration-Webhooks Regards,

              People

              • Assignee:
                rsandell rsandell
                Reporter:
                carlosrodlop Carlos Rodríguez López
              • Votes:
                1 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: