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

Multibranch pipeline project jobs are not deleted when branches are deleted

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • git-plugin
    • None
    • git-plugin compiled from master.
      This bug does not exist in git-plugin 2.5.3

      Problem

      If you compile git-plugin from the source, and set 'Discard old items' in the multibranch pipeline, deleted branches on the SCM are not deleted from the job list. If you install the 2.5.3 version of this plugin and restart Jenkins, these branches are deleted.

      How to reproduce it

      Configure a Jenkins installation

      1. Download a fresh Jenkins (2.7.2), rename your current home
      2. Start it: java -jar jenkins.war
      3. Choose the default packages option during the first boot
      4. Clone git-plugin repository, compile it (mvn.cmd '-Dmaven.test.skip=true' clean install hpi:hpi)
      5. Import your git-plugin (the one you compiled) in Jenkins (advanced tab)
      6. Restart Jenkins

      See the error

      1. Create a test git repository with a Jenkinsfile on many branches
      2. Add a new multibranch pipeline, select "Discard old items"
      3. Save, check that your branches appear in the list
      4. Delete a branch from your repository. git push origin :features/a-random-branch
      5. Run a branch indexing
      6. See that your branch was not deleted

      Check that 2.5.3 is working

      1. Restore the git-plugin in its original version, 2.5.3
      2. Restart Jenkins
      3. Rerun branch indexing, see that your branch has disappeared !

      Investigations

      I didn't have the time to run a Jenkins instance in debug, or to read the commits yet. So I've no idea why this bug happens. I'll update this section later if I've time.

          [JENKINS-37727] Multibranch pipeline project jobs are not deleted when branches are deleted

          Quentin Dufour created issue -
          Quentin Dufour made changes -
          Summary Original: Branches of multibranch pipelines are not anymore deleted in upstream New: Jobs of a multibranch pipeline project are not anymore deleted in upstream
          Quentin Dufour made changes -
          Description Original: h2. Problem

          If you compile git-plugin from the source, and set 'Discard old items' in the multibranch pipeline, deleted branches on the SCM are not deleted from the job list. If you install the 2.5.3 version of this plugin and restart Jenkins, these branches are deleted.

          h2. How to reproduce it

          # Download a fresh Jenkins (2.7.2), rename your current home
          # Start it: java -jar jenkins.war
          # Choose the default packages for the first boot
          # Clone git-plugin repository, compile it (mvn.cmd '-Dmaven.test.skip=true' clean install hpi:hpi)
          # Import your git-plugin (the one you compiled) in Jenkins (advanced tab)
          # Restart Jenkins
          # Create a test git repository with a Jenkinsfile on many branches
          # Add a new multibranch pipeline, select "Discard old items"
          # Save, check that your branches appear in the list
          # Delete a branch from your repository. git push origin :features/a-random-branch
          # Run a branch indexing
          # See that your branch was not deleted
          # Restore the git-plugin in its original version, 2.5.3
          # Restart Jenkins
          # Rerun branch indexing, see that your branch has disappeared !
          New: h2. Problem

          If you compile git-plugin from the source, and set 'Discard old items' in the multibranch pipeline, deleted branches on the SCM are not deleted from the job list. If you install the 2.5.3 version of this plugin and restart Jenkins, these branches are deleted.

          h2. How to reproduce it

          *Configure a Jenkins installation*

          # Download a fresh Jenkins (2.7.2), rename your current home
          # Start it: java -jar jenkins.war
          # Choose the default packages option during the first boot
          # Clone git-plugin repository, compile it (mvn.cmd '-Dmaven.test.skip=true' clean install hpi:hpi)
          # Import your git-plugin (the one you compiled) in Jenkins (advanced tab)
          # Restart Jenkins

          *See the error*

          # Create a test git repository with a Jenkinsfile on many branches
          # Add a new multibranch pipeline, select "Discard old items"
          # Save, check that your branches appear in the list
          # Delete a branch from your repository. git push origin :features/a-random-branch
          # Run a branch indexing
          # See that your branch was not deleted

          *Check that 2.5.3 is working*

          # Restore the git-plugin in its original version, 2.5.3
          # Restart Jenkins
          # Rerun branch indexing, see that your branch has disappeared !
          Quentin Dufour made changes -
          Description Original: h2. Problem

          If you compile git-plugin from the source, and set 'Discard old items' in the multibranch pipeline, deleted branches on the SCM are not deleted from the job list. If you install the 2.5.3 version of this plugin and restart Jenkins, these branches are deleted.

          h2. How to reproduce it

          *Configure a Jenkins installation*

          # Download a fresh Jenkins (2.7.2), rename your current home
          # Start it: java -jar jenkins.war
          # Choose the default packages option during the first boot
          # Clone git-plugin repository, compile it (mvn.cmd '-Dmaven.test.skip=true' clean install hpi:hpi)
          # Import your git-plugin (the one you compiled) in Jenkins (advanced tab)
          # Restart Jenkins

          *See the error*

          # Create a test git repository with a Jenkinsfile on many branches
          # Add a new multibranch pipeline, select "Discard old items"
          # Save, check that your branches appear in the list
          # Delete a branch from your repository. git push origin :features/a-random-branch
          # Run a branch indexing
          # See that your branch was not deleted

          *Check that 2.5.3 is working*

          # Restore the git-plugin in its original version, 2.5.3
          # Restart Jenkins
          # Rerun branch indexing, see that your branch has disappeared !
          New: h2. Problem

          If you compile git-plugin from the source, and set 'Discard old items' in the multibranch pipeline, deleted branches on the SCM are not deleted from the job list. If you install the 2.5.3 version of this plugin and restart Jenkins, these branches are deleted.

          h2. How to reproduce it

          *Configure a Jenkins installation*

          # Download a fresh Jenkins (2.7.2), rename your current home
          # Start it: java -jar jenkins.war
          # Choose the default packages option during the first boot
          # Clone git-plugin repository, compile it (mvn.cmd '-Dmaven.test.skip=true' clean install hpi:hpi)
          # Import your git-plugin (the one you compiled) in Jenkins (advanced tab)
          # Restart Jenkins

          *See the error*

          # Create a test git repository with a Jenkinsfile on many branches
          # Add a new multibranch pipeline, select "Discard old items"
          # Save, check that your branches appear in the list
          # Delete a branch from your repository. git push origin :features/a-random-branch
          # Run a branch indexing
          # See that your branch was not deleted

          *Check that 2.5.3 is working*

          # Restore the git-plugin in its original version, 2.5.3
          # Restart Jenkins
          # Rerun branch indexing, see that your branch has disappeared !

          h2. Investigations

          I didn't have the time to run a Jenkins instance in debug, or to read the commits yet. So I've no idea why this bug happens. I'll update this section later if I've time.

          Mark Waite added a comment - - edited

          Thanks for catching that bug before release!

          The master branch adds command line git support for multi-branch pipelines, and makes command line git the default (just as command line git is the default in other cases). Unfortunately, the calling sequence which worked for JGit (fetch() followed by prune()) behaves better in JGit than CliGit. Changing the calling sequence to fetch_().prune().execute() fixes the issue for both JGit and CliGit).

          I was able to duplicate the problem as reported. It is included in my bug verification docker instance and references the JENKINS-37727 branch of my jenkins-bugs repository.

          If I change the job definition from using the command line git implementation to use the jgit implementation, the jobs which correspond to deleted branches are removed, so long as the local branch extension is not enabled (create a branch for each build). If the local branch extension is enabled, or if I switch from jgit to the command line implementation, the jobs which correspond to deleted branches are not removed.

          I suspect there may be two problems here.

          1. If the local branch extension is enabled, I suspect that the cache repository (used to extract the Jenkinsfile) performs a checkout to a named branch matching the target branch. That checkout of a named branch in the cache repository is necessary (to extract the Jenkinsfile), but it does not need to checkout as a named branch. It can use a detached head checkout.
          2. Command line git branch pruning doesn't seem to be working in the cache

          I marked this as critical, since users will not want to modify their multi-branch job definitions to use JGit, especially since there are authentication cases which command git can handle that JGit cannot.

          I've found what appears to be a clean fix for the problem. Unit test and integration test are both available to confirm the problem is fixed. The unit test could use some further work to assure it tests both the CliGit and JGit implementations, but that will need to wait for another time.

          Mark Waite added a comment - - edited Thanks for catching that bug before release! The master branch adds command line git support for multi-branch pipelines, and makes command line git the default (just as command line git is the default in other cases). Unfortunately, the calling sequence which worked for JGit (fetch() followed by prune()) behaves better in JGit than CliGit. Changing the calling sequence to fetch_().prune().execute() fixes the issue for both JGit and CliGit). I was able to duplicate the problem as reported. It is included in my bug verification docker instance and references the JENKINS-37727 branch of my jenkins-bugs repository . If I change the job definition from using the command line git implementation to use the jgit implementation, the jobs which correspond to deleted branches are removed, so long as the local branch extension is not enabled (create a branch for each build). If the local branch extension is enabled, or if I switch from jgit to the command line implementation, the jobs which correspond to deleted branches are not removed. I suspect there may be two problems here. If the local branch extension is enabled, I suspect that the cache repository (used to extract the Jenkinsfile) performs a checkout to a named branch matching the target branch. That checkout of a named branch in the cache repository is necessary (to extract the Jenkinsfile), but it does not need to checkout as a named branch. It can use a detached head checkout. Command line git branch pruning doesn't seem to be working in the cache I marked this as critical, since users will not want to modify their multi-branch job definitions to use JGit, especially since there are authentication cases which command git can handle that JGit cannot. I've found what appears to be a clean fix for the problem . Unit test and integration test are both available to confirm the problem is fixed. The unit test could use some further work to assure it tests both the CliGit and JGit implementations, but that will need to wait for another time.
          Mark Waite made changes -
          Summary Original: Jobs of a multibranch pipeline project are not anymore deleted in upstream New: Jobs of a multibranch pipeline project are not anymore deleted in upstream if "/" in branch name
          Mark Waite made changes -
          Summary Original: Jobs of a multibranch pipeline project are not anymore deleted in upstream if "/" in branch name New: Jobs of a multibranch pipeline project are not deleted when branch is deleted
          Mark Waite made changes -
          Priority Original: Minor [ 4 ] New: Critical [ 2 ]
          Mark Waite made changes -
          Summary Original: Jobs of a multibranch pipeline project are not deleted when branch is deleted New: Jobs of a multibranch pipeline project are not deleted when branches are deleted
          Mark Waite made changes -
          Summary Original: Jobs of a multibranch pipeline project are not deleted when branches are deleted New: Multibranch pipeline project jobs are not deleted when branches are deleted

            markewaite Mark Waite
            superboum Quentin Dufour
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: