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

Hook uninstalled if job is in a subfolder

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Component/s: github-plugin
    • Labels:
    • Environment:
      Jenkins ver. 1.565.3, GitHub plugin 1.9.1, CloudBees Folders Plugin 4.6.1
    • Similar Issues:

      Description

      After I started using the CloudBees Folders Plugin and moving jobs into folders, I noticed when I pushed stuff to github, builds were no longer triggered. I checked in GitHub and the Jenkins plugin was not enabled. I go to the job, save it again (the option "Build when a change is pushed to GitHub" is always checked and is the only method to trigger a build that's activated) and I see the hook is created, but after a minute or 2, it gets removed again. GitHub security log says the removal request comes from the Jenkins server.

      Looking at the source code, I see where hooks are being removed:
      https://github.com/jenkinsci/github-plugin/blob/49bc59d79707808d73eb0f9d5c97996fd5525d08/src/main/java/com/cloudbees/jenkins/Cleaner.java

      Activating the log for com.cloudbees.jenkins.Cleaner I can definitely see it's Jenkins the one removing the hooks. Why is considering jobs inside subfolders as "not interesting" I have no idea.

        Attachments

          Activity

          lucasocio Leandro Lucarella created issue -
          lucasocio Leandro Lucarella made changes -
          Field Original Value New Value
          Description After I started using the CloudBees Folders Plugin and moving jobs into folders, I noticed when I pushed stuff to github, builds were no longer triggered. I checked in GitHub and the Jenkins plugin was not enabled. I go to the job, save it again (the option "Build when a change is pushed to GitHub" is always checked and is the only method to trigger a build that's activated) and I see the hook is created, but after a minute or 2, it gets removed again. GitHub security log says the removal request comes from the Jenkins server.

          Looking at the source code, I see where hooks are being removed:
          https://github.com/jenkinsci/github-plugin/blob/49bc59d79707808d73eb0f9d5c97996fd5525d08/src/main/java/com/cloudbees/jenkins/Cleaner.java

          Activating the log for com.cloudbees.jenkins.Cleaner I can definitely see it's Jenkins the one removing the hooks. Why is considering jobs inside subfolders as "not interesting" I have no idea.

          Looking at the "GitHub Hook Log" for a top-level project, I see something like this:
          ---
          Last GitHub Push

          Started on Oct 13, 2014 3:21:08 PM
          Polling SCM changes on master
          Using strategy: Default
          [poll] Last Built Revision: Revision ae6386642259cb1b675730fbce96deaa29d3a369 (origin/master)
           > git rev-parse --is-inside-work-tree # timeout=10
          Fetching changes from the remote Git repositories
           > git config remote.origin.url git@github.com:sociomantic/git-hub.git # timeout=10
          Fetching upstream changes from git@github.com:sociomantic/git-hub.git
           > git --version # timeout=10
          using GIT_SSH to set credentials GitHub jenkins-admin
           > git fetch --tags --progress git@github.com:sociomantic/git-hub.git +refs/heads/*:refs/remotes/origin/*
          Polling for changes in
          Seen branch in repository origin/master
           > git log --full-history --no-abbrev --format=raw -M -m --raw ae6386642259cb1b675730fbce96deaa29d3a369..7618cac3f33deb84868332acc64572b60d7adf7e # timeout=10
          Done. Took 3.4 sec
          Changes found
          ---

          (I don't know why is it polling anything in the first place because Polling is not enabled)

          For a job in a subfolder, I see this log instead:
          ---
          After I started using the CloudBees Folders Plugin and moving jobs into folders, I noticed when I pushed stuff to github, builds were no longer triggered. I checked in GitHub and the Jenkins plugin was not enabled. I go to the job, save it again (the option "Build when a change is pushed to GitHub" is always checked and is the only method to trigger a build that's activated) and I see the hook is created, but after a minute or 2, it gets removed again. GitHub security log says the removal request comes from the Jenkins server.

          Looking at the source code, I see where hooks are being removed:
          https://github.com/jenkinsci/github-plugin/blob/49bc59d79707808d73eb0f9d5c97996fd5525d08/src/main/java/com/cloudbees/jenkins/Cleaner.java

          Activating the log for com.cloudbees.jenkins.Cleaner I can definitely see it's Jenkins the one removing the hooks. Why is considering jobs inside subfolders as "not interesting" I have no idea.
          Show
          danielbeck Daniel Beck added a comment - This line is bogus, needs to be getAllItems(...) : https://github.com/jenkinsci/github-plugin/blob/49bc59d79707808d73eb0f9d5c97996fd5525d08/src/main/java/com/cloudbees/jenkins/Cleaner.java#L55
          Hide
          lucasocio Leandro Lucarella added a comment -

          I don't have a Java development environment, but I would be very much interested in testing a fix if someone can provide it

          Show
          lucasocio Leandro Lucarella added a comment - I don't have a Java development environment, but I would be very much interested in testing a fix if someone can provide it
          danielbeck Daniel Beck made changes -
          Labels folders
          Hide
          ryangardner ryangardner added a comment -

          I sent a pull request with the above fix. It fixed the issue for me.

          https://github.com/jenkinsci/github-plugin/pull/51#issuecomment-84089491

          Show
          ryangardner ryangardner added a comment - I sent a pull request with the above fix. It fixed the issue for me. https://github.com/jenkinsci/github-plugin/pull/51#issuecomment-84089491
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Ryan Gardner
          Path:
          src/main/java/com/cloudbees/jenkins/Cleaner.java
          http://jenkins-ci.org/commit/github-plugin/2a49bac65fb7e05cd083e8b445ad2fcfb689ae0a
          Log:
          Address JENKINS-25127 by using getAllIItems instead of getItems

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Ryan Gardner Path: src/main/java/com/cloudbees/jenkins/Cleaner.java http://jenkins-ci.org/commit/github-plugin/2a49bac65fb7e05cd083e8b445ad2fcfb689ae0a Log: Address JENKINS-25127 by using getAllIItems instead of getItems
          Hide
          lucasocio Leandro Lucarella added a comment -

          Nice! ETA for a release with this fix?

          Show
          lucasocio Leandro Lucarella added a comment - Nice! ETA for a release with this fix?
          Hide
          lucasocio Leandro Lucarella added a comment -

          Oh, I see 1.11.1 is out, thanks!

          Is there any way to tell all the jobs to re-register in GitHub? Right now the only way I could find to do this is to go to each jobs's config and save it again, which is a bit impractical when you have many jobs.

          Thanks!

          Show
          lucasocio Leandro Lucarella added a comment - Oh, I see 1.11.1 is out, thanks! Is there any way to tell all the jobs to re-register in GitHub? Right now the only way I could find to do this is to go to each jobs's config and save it again, which is a bit impractical when you have many jobs. Thanks!
          Hide
          integer Kanstantsin Shautsou added a comment -

          Hi, please try restart jenkins.

          Show
          integer Kanstantsin Shautsou added a comment - Hi, please try restart jenkins.
          Hide
          lucasocio Leandro Lucarella added a comment -

          It doesn't help.

          Show
          lucasocio Leandro Lucarella added a comment - It doesn't help.
          Hide
          integer Kanstantsin Shautsou added a comment -

          Sorry have no idea.

          Show
          integer Kanstantsin Shautsou added a comment - Sorry have no idea.
          Hide
          integer Kanstantsin Shautsou added a comment -

          Closing because issue should be fixed.

          Show
          integer Kanstantsin Shautsou added a comment - Closing because issue should be fixed.
          integer Kanstantsin Shautsou made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Hide
          danielbeck Daniel Beck added a comment -

          Kanstantsin Shautsou Did you confirm the fix is complete?

          Show
          danielbeck Daniel Beck added a comment - Kanstantsin Shautsou Did you confirm the fix is complete?
          Hide
          integer Kanstantsin Shautsou added a comment -

          Feel free to check.

          Show
          integer Kanstantsin Shautsou added a comment - Feel free to check.
          Hide
          danielbeck Daniel Beck added a comment -

          Kanstantsin Shautsou You resolved this despite a report it's not actually fixed, not me.

          Show
          danielbeck Daniel Beck added a comment - Kanstantsin Shautsou You resolved this despite a report it's not actually fixed, not me.
          Hide
          integer Kanstantsin Shautsou added a comment -

          I tired from your spam comments. Commit was done with fix but has no FIXED prefix to automatically close issue. If issue persist, then requester will reopen. If you want handle this issue and plugin maintaining then go!

          Show
          integer Kanstantsin Shautsou added a comment - I tired from your spam comments. Commit was done with fix but has no FIXED prefix to automatically close issue. If issue persist, then requester will reopen. If you want handle this issue and plugin maintaining then go!
          Hide
          orrc Christopher Orr added a comment -

          Leandro Lucarella: Just a quick comment; I haven't tested this code, but you should be able to use the Jenkins Script Console to re-save all affected jobs. Saving the job config should cause the hook to be created on GitHub:

          for (job in Jenkins.instance.getAllItems(AbstractProject.class)) {
            if (job.getTrigger(GitHubPushTrigger.class) != null) {
              println("Saving " + job);
              job.save();
            }
          }
          

          You'll probably have to add some "import" statements at the top for the relevant classes.

          Or if you want test it first on individual jobs, you can get a single job like this: Jenkins.instance.getItem('job-name-goes-here')

          Show
          orrc Christopher Orr added a comment - Leandro Lucarella : Just a quick comment; I haven't tested this code, but you should be able to use the Jenkins Script Console to re-save all affected jobs. Saving the job config should cause the hook to be created on GitHub: for (job in Jenkins.instance.getAllItems(AbstractProject.class)) { if (job.getTrigger(GitHubPushTrigger.class) != null) { println("Saving " + job); job.save(); } } You'll probably have to add some "import" statements at the top for the relevant classes. Or if you want test it first on individual jobs, you can get a single job like this: Jenkins.instance.getItem('job-name-goes-here')
          Hide
          danielbeck Daniel Beck added a comment -

          Kanstantsin Shautsou cleared up my confusion on IRC: The hooks that have been removed are gone. You need to reconfigure them in Jenkins to have them re-register. At least with the fix, they should not be getting removed again.

          Show
          danielbeck Daniel Beck added a comment - Kanstantsin Shautsou cleared up my confusion on IRC: The hooks that have been removed are gone. You need to reconfigure them in Jenkins to have them re-register. At least with the fix, they should not be getting removed again.
          Hide
          integer Kanstantsin Shautsou added a comment -

          Plugin may provide some helper method that should re-calculated hooks, but i have no time for checking. Such method may be triggered from script console or even from button in global page.

          Show
          integer Kanstantsin Shautsou added a comment - Plugin may provide some helper method that should re-calculated hooks, but i have no time for checking. Such method may be triggered from script console or even from button in global page.
          Hide
          lucasocio Leandro Lucarella added a comment -

          I tried the script but I get this error:
          groovy.lang.MissingPropertyException: No such property: GitHubPushTrigger for class: Script1

          I don't know anything about groovy or java, that means I need an import?

          Show
          lucasocio Leandro Lucarella added a comment - I tried the script but I get this error: groovy.lang.MissingPropertyException: No such property: GitHubPushTrigger for class: Script1 I don't know anything about groovy or java, that means I need an import?
          Hide
          integer Kanstantsin Shautsou added a comment -

          Hi, you need

           import com.cloudbees.jenkins.GitHubPushTrigger 
          Show
          integer Kanstantsin Shautsou added a comment - Hi, you need import com.cloudbees.jenkins.GitHubPushTrigger
          Hide
          lucasocio Leandro Lucarella added a comment -

          Thanks a lot! The script have worked (I got the expected println() output) but no re-registration of hooks to GitHub happened :-/

          Show
          lucasocio Leandro Lucarella added a comment - Thanks a lot! The script have worked (I got the expected println() output) but no re-registration of hooks to GitHub happened :-/
          Hide
          integer Kanstantsin Shautsou added a comment -

          Leandro Lucarella, let's try to clarify:
          1) is initial issue was fixed in new release? First user confirmed that it prevents hooks clean up

          Show
          integer Kanstantsin Shautsou added a comment - Leandro Lucarella, let's try to clarify: 1) is initial issue was fixed in new release? First user confirmed that it prevents hooks clean up
          Hide
          lucasocio Leandro Lucarella added a comment -

          Yes, at least I tried with one job to manually save it and the hook was installed and not removed afterward. I'll try again, saving a couple more jobs manually, and report back, just in case.

          Show
          lucasocio Leandro Lucarella added a comment - Yes, at least I tried with one job to manually save it and the hook was installed and not removed afterward. I'll try again, saving a couple more jobs manually, and report back, just in case.
          Hide
          lucasocio Leandro Lucarella added a comment -

          I tried with a couple more jobs to save them manually and the hooks were properly registered and never removed again. Is only the script to save all the jobs in a batch that doesn't work for me.

          Show
          lucasocio Leandro Lucarella added a comment - I tried with a couple more jobs to save them manually and the hooks were properly registered and never removed again. Is only the script to save all the jobs in a batch that doesn't work for me.
          Hide
          integer Kanstantsin Shautsou added a comment -

          According to code hooks registered during trigger start, all triggers will start during jenkins start-up. So jenkins restart should help.
          Please add in your Jenkins -> manage -> system log, new logger for package "com.cloudbees.jenkins" with level ALL. Restart jenkins and check this log.

          Show
          integer Kanstantsin Shautsou added a comment - According to code hooks registered during trigger start, all triggers will start during jenkins start-up. So jenkins restart should help. Please add in your Jenkins -> manage -> system log, new logger for package "com.cloudbees.jenkins" with level ALL. Restart jenkins and check this log.
          Hide
          lucasocio Leandro Lucarella added a comment -

          What am I looking for in this log?

          Show
          lucasocio Leandro Lucarella added a comment - What am I looking for in this log?
          Hide
          integer Kanstantsin Shautsou added a comment -

          That all hooks where registered for projects that you expect

           LOGGER.log(Level.INFO, "Adding GitHub webhooks for {0}", names); 
          Show
          integer Kanstantsin Shautsou added a comment - That all hooks where registered for projects that you expect LOGGER.log(Level.INFO, "Adding GitHub webhooks for {0}" , names);
          Hide
          integer Kanstantsin Shautsou added a comment -

          Hi, restart wouldn't help. As orrc mentioned hook is registered only when newInstance argument for .start() is true.
          I split this functionality to separate method to have ability to call it from groovy and added button in global page.
          Proposed PR https://github.com/jenkinsci/github-plugin/pull/52/files

          Show
          integer Kanstantsin Shautsou added a comment - Hi, restart wouldn't help. As orrc mentioned hook is registered only when newInstance argument for .start() is true. I split this functionality to separate method to have ability to call it from groovy and added button in global page. Proposed PR https://github.com/jenkinsci/github-plugin/pull/52/files
          Hide
          integer Kanstantsin Shautsou added a comment -

          Please test this PR https://github.com/jenkinsci/github-plugin/pull/52 , you can pick built hpi from commit status link.

          Show
          integer Kanstantsin Shautsou added a comment - Please test this PR https://github.com/jenkinsci/github-plugin/pull/52 , you can pick built hpi from commit status link.
          Hide
          lucasocio Leandro Lucarella added a comment -

          I tested the PR and the re-register button seems to work fine, thanks!

          Show
          lucasocio Leandro Lucarella added a comment - I tested the PR and the re-register button seems to work fine, thanks!
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Kanstantsin Shautsou
          Path:
          src/main/java/com/cloudbees/jenkins/GitHubPushTrigger.java
          src/main/resources/com/cloudbees/jenkins/GitHubPushTrigger/global.jelly
          http://jenkins-ci.org/commit/github-plugin/6154cedfe18f265aea25756284a3472696eceaff
          Log:
          JENKINS-25127 Add Button for registering all hooks

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Kanstantsin Shautsou Path: src/main/java/com/cloudbees/jenkins/GitHubPushTrigger.java src/main/resources/com/cloudbees/jenkins/GitHubPushTrigger/global.jelly http://jenkins-ci.org/commit/github-plugin/6154cedfe18f265aea25756284a3472696eceaff Log: JENKINS-25127 Add Button for registering all hooks
          rtyler R. Tyler Croy made changes -
          Workflow JNJira [ 159033 ] JNJira + In-Review [ 195973 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              lucasocio Leandro Lucarella
            • Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: