-
Bug
-
Resolution: Won't Fix
-
Minor
-
Jenkins 2.46.2
Git Plugin 3.3.0
Pipeline: Multibranch 2.16
Today i was wondering why a branch that was deleted on the remote repository does not get marked as removed in the Pipeline Multibranch Projekt.
So I did a couple of "Scan Multibranch Pipeline Now" and had a closer look at the log, but while the statements seemed ok in the first place, the branches are still all listed and even though a prune option is on the fetch they did not get removed.
> /usr/bin/git rev-parse --is-inside-work-tree # timeout=10 Setting origin to gitserver:/data/git/Repository.git > /usr/bin/git config remote.origin.url gitserver:/data/git/Repository.git # timeout=10 Fetching origin... Fetching upstream changes from origin > /usr/bin/git --version # timeout=10 using GIT_SSH to set credentials Jenkins private Key zur Authentifizierung auf gitserver > /usr/bin/git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/* using GIT_SSH to set credentials Jenkins private Key zur Authentifizierung auf gitserver > /usr/bin/git ls-remote gitserver:/data/git/Repository.git # timeout=10 > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10 Setting origin to gitserver:/data/git/Repository.git > /usr/bin/git config remote.origin.url gitserver:/data/git/Repository.git # timeout=10 Fetching & pruning origin... Fetching upstream changes from origin > /usr/bin/git --version # timeout=10 using GIT_SSH to set credentials Jenkins private Key zur Authentifizierung auf gitserver > /usr/bin/git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/* --prune Getting remote branches... Seen branch in repository origin/bugfix/JIRA-6365 Seen branch in repository origin/development Seen branch in repository origin/release/14.1 ...
so i was looking into the <JENKINS_HOME>/cache directory and fired a couple of git commands manually:
git prune git fetch --prune git remote prune origin
but nothing happened to the refs/remotes/origin/bugfix... (that should haved been removed)
after more investigation I stumbled upon the following command and compared the output to my local copy and the surprise was that all branches in the jenkins cache does not seem to be tracked:
# in the Jenkins cache (used for the multi branch indexing) git remote show origin * remote origin Fetch URL: gitserver:/data/git/Repository.git Push URL: gitserver:/data/git/Repository.git HEAD branch: development
# locally cloned repository git remote show origin * remote origin Fetch URL: gitserver:/data/git/Repository.git Push URL: gitserver:/data/git/Repository.git HEAD branch: development Remote branches: bugfix/JIRA-6365 tracked development tracked release/14.1 tracked Local branches configured for 'git pull': ... Local refs configured for 'git push': ...
The only difference I could find was that in the .git/config
[remote "origin"] url = gitserver:/data/git/Repository.git fetch = +refs/heads/*:refs/remotes/origin/*
the fetch line was missing. After I added that in a local copy and made a git fetch --prune the stale branches got removed.
git fetch --prune From gitserver:/data/git/Repository.git - [deleted] (none) -> origin/bugfix/JIRA-6365
I also replayed the commands from the Multibranch Scan Log with a local git (git version 2.13.0.windows.1) and had the same problems - the remote references where fetched but not tracked.
I hope I did not miss a thing here and you can fix this.
Update: Jenkins is using the command line git in version 1.7.1
I think that the multi-branch pipeline does not depend on the setting of "prune stale remote tracking branches". There are settings in the multi-branch pipeline job configuration ("Advanced" section, I believe) which control what should be done when remote branches have been deleted. I don't think that you want to set the git plugin option "Prune stale remote-tracking branches". Rather, you want to configure the expiration period for deleted branches to be 0 so that they will be removed immediately.
You could enable JGit on your master, configure the multi-branch job to use it, and see if the behavior improves. JGit is a pure Java implementation of a subset of the command line git features. It works well in many use cases (though not all).
Command line git version 1.7.1 is old enough that it is not officially supported by the git plugin. The git plugin wiki page notes that it needs at least 1.7.10. I continue to test with command line git 1.7.1 in my automation environment because it is still available on CentOS 6. However, there are many git operations which simply don't work on command line git 1.7.1. I frequently annotate tests to avoid running on older versions like git 1.7.1.
There are authentication use cases which don't work, submodule use cases which don't work, sparse checkout use cases which don't work, large file support uses cases which don't work, and shallow clone use cases which don't work. I'm sure there are others.
I think that the case you're seeing is not related to command line git version number, but wanted to be sure you understand that command line git versions older than 1.7.10 are only tracked on a best effort basis, and there are many functions which don't work and won't ever work.