Branch Indexing fails with 'Could not fetch branches from source' error

Article ID:360048256552
2 minute readKnowledge base

Issue

  • After configuring a Multibranch Pipeline job, Branch Indexing fails with:

ERROR: [Thu Jul 30 14:00:15 CDT 2020] Could not fetch branches from source xxxxx-xxxxx-xxxx-xxxx-xxxxx
hudson.plugins.git.GitException: Command "/bin/git fetch --tags --progress --prune origin +refs/heads/*:refs/remotes/origin/*" returned status code 1:
stdout:
stderr: error: unable to resolve reference refs/remotes/origin/<branchName>: Not a directory
From <branchSourceUrl>
 ! [new branch]      <branchName> -> origin/<branchName>  (unable to update local ref)
error: some local refs could not be updated; try running
 'git remote prune origin' to remove any old, conflicting branches

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2430)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2044)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:81)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:569)
	at jenkins.plugins.git.AbstractGitSCMSource$8.run(AbstractGitSCMSource.java:575)
	at jenkins.plugins.git.AbstractGitSCMSource$8.run(AbstractGitSCMSource.java:561)
	at jenkins.plugins.git.AbstractGitSCMSource.doRetrieve(AbstractGitSCMSource.java:372)
	at jenkins.plugins.git.AbstractGitSCMSource.retrieve(AbstractGitSCMSource.java:561)
	at jenkins.scm.api.SCMSource._retrieve(SCMSource.java:373)
	at jenkins.scm.api.SCMSource.fetch(SCMSource.java:283)
	at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:641)
	at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:277)
	at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:164)
	at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:1032)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:427)

Workaround

When the Multibranch Pipeline project scans the remote repository, it fetches the git repo data and stores it on the Jenkins controller in a subdirectory of $JENKINS_HOME/caches. It is possible for this cached repository to become corrupt, preventing the scan from finishing successfully. If this occurs, please contact CloudBees Support so they can collect the necessary data to determine root cause. As a workaround, this cached git repo can be safely deleted, which will cause the Multibranch Pipeline plugin to re-fetch the repository data.

The cached git repos are stored under $JENKINS_HOME/caches in a subdirectory consisting of git-<hash(remoteProjectUrl)> + a hashed value of the project repository URL. To identify the correct cache subdirectory for your multibranch pipeline project, run the following script in Jenkins Script Console to compute the hash of the remote URL:

"git-" + Util.getDigestOf("<gitRemoteUrl>")

For example, given a repository URL of "https://bitbucket.example.com/scm/my-project.git", the cached git repo would be stored under $JENKINS_HOME/caches/git-6a303d5f2e994e8a1507fec7657ea43a

Remove this directory, then manually trigger a scan of the Multibranch Pipeline project from the Jenkins UI. For example,

rm -rf $JENKINS_HOME/caches/git-6a303d5f2e994e8a1507fec7657ea43a

If the scan is successful, a new cache folder will be created.