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

GitParameter not cleaning up stale ref branch

XMLWordPrintable

    • Declarative backlog

      But I don't like manual work as this issue kept coming once in a while. I wonder if there is a way to tell gitParameter to prune the stale reference. Thanks!

      Summary

      I have issue with Git. This is the issue in my Jenkins server when using gitParameter parameter. I'm using git-parameter:0.9.18 plugin in my Pipeline input parameters where the pipeline user can choose the release branch they want to build and deploy. I'm using GitHub as my code repository as well.

      @Library("myCiCdLib")
      properties([
          steps.parameters([
              gitParameter(
                    branch: '',
                    branchFilter: 'origin/(release/.*)',
                    defaultValue: 'master',
                    description: 'Git branch to deploy',
                    name: 'BRANCH',
                    quickFilterEnabled: false,
                    selectedValue: 'NONE',
                    sortMode: 'DESCENDING',
                    type: 'PT_BRANCH'
                  ),
          ])
      ])
      
      pipeline {
      
        stages {
           stage("Build"){
              make build
              echo "Whatever steps ..."
           }
           # ... the rest of the pipeline
        }
      }

      The problem may or may not related to Jenkins or the git plugins. But what happen is we have a branch called feature-abc in origin a week ago and when the Pull Request from that branch got merged a week ago, GitHub automatically deleted the feature-abc branch in origin repository.

      Jenkins might also have pulled this branch into its workspace and run the pipeline. Now we have two other  branches we had just today called

      • feature-abc /navbar 
      • feature-abc/menu .

      Notice the name has same prefix with branch feature-abc .

      The issue:

      error: cannot lock ref 'refs/remotes/origin/feature-abc/menu': 'refs/remotes/origin/feature-abc' exists;
      cannot create 'refs/remotes/origin/feature-abc/navbar' From https://github.com/MyOrg/mywebapp
      
      ! [new branch] feature-abc/navbar -> origin/feature-abc/navbar (unable to update local ref) 
         error: cannot lock ref 'refs/remotes/origin/feature-abc/navbar': 'refs/remotes/origin/feature-abc' exists; 
         cannot create 'refs/remotes/origin/feature-abc/navbar'
      
      ! [new branch] feature-abc/menubar -> origin/feature-abc/menubar (unable to update local ref)
         error: cannot lock ref 'refs/remotes/origin/feature-abc/menubar': 'refs/remotes/origin/feature-abc' exists; 
         cannot create 'refs/remotes/origin/feature-abc/menubar'

       

      The solution I know is by running the following in the jenkins master server node.

      git fetch --prune origin

      But I don't like manual work as this issue kept coming once in a while. I wonder if there is a way to tell gitParameter to prune the stale reference. Thanks!

            klimas7 Boguslaw Klimas
            danarbo Dan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: