Skip to content

[JENKINS-71512] GitParameter not cleaning up stale ref branch #301

@jenkins-infra-bot

Description

@jenkins-infra-bot

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!


Originally reported by danarbo, imported from: GitParameter not cleaning up stale ref branch
  • status: Open
  • priority: Major
  • component(s): git-parameter-plugin
  • label(s): git, jenkins, plugin, plugins
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 20251216-182730
Raw content of original issue

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!

  • environment: Docker Image: jenkins/jenkins:2.401.1-jdk11

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions