10

I'm trying to create a release from Maven, but I'm getting a git tag already exists error, even though I have deleted that tag from both my local machine and the remote repository.

This question has the same issue, but for Bamboo rather than Jenkins. The solution was to delete a file in Bamboo that caches the Git configuration:

<BAMBOO_HOME>/xml-data/build-dir/_git-repositories-cache

How can I do the same thing with Jenkins?

Community
  • 1
  • 1
bsky
  • 19,326
  • 49
  • 155
  • 270

1 Answers1

13

Ran into the same thing today, found the git repository cached on my master at /var/lib/jenkins/caches if you have lots of git repos you will need to try and find your specific one since they are listed by hashes and not by name.

[jenkins@jenkinsmaster caches]$ pwd
/var/lib/jenkins/caches
[jenkins@jenkinsmaster caches]$ ls -als
...
4 drwxr-xr-x.  3 jenkins jenkins 4096 Nov  8 09:10 git-bbcfdeb24494d83c13621c40b3b14ffd
4 drwxr-xr-x.  2 jenkins jenkins 4096 Nov  8 09:10 git-bbcfdeb24494d83c13621c40b3b14ffd@tmp
...

Once I found the correct one ( by going into each and running a git tag -l looking for my unwanted tags. I just deleted the git-<hash> and git-<hash>@tmp folders from that directory. Re-ran my Job and the source was fully checked out again and did not have the unwanted tags. :^)

Note that, as commented below, in the Jenkins script console you can run:
println('git-'+hudson.Util.getDigestOf('remote')) where remote is the the URL of the git remote, to identify the correct cache.

SiHa
  • 7,830
  • 13
  • 34
  • 43
Sean
  • 643
  • 8
  • 10
  • Superb! Thanks a lot! After a Jenkins crash I had all kinds of weird git-fetch messages. They vanished all! – tm1701 Nov 07 '18 at 15:57
  • 2
    If you have access to the Script Console, you can find the name of the cache directory with: `println('git-'+hudson.Util.getDigestOf(remote))` where remote is the actual URL/remote string you're using for the git repo – Craig Kelly Apr 02 '19 at 18:37
  • 5
    Is it safe to cleanup the entire /var/lib/jenkins/caches/* ? – Rahul Mohan Sep 26 '19 at 13:09
  • Wondering same @RahulMohan Did you remove it and does it causes problem if deleted – Tara Prasad Gurung Jul 06 '20 at 12:40
  • 2
    I removed /var/lib/jenkins/caches/* without any issues – sancelot Aug 05 '20 at 13:07
  • Can this be done using some command in the script or config section of the jenkins ? The jenkins is centrally managed and it is not possible to access the instance where the Jenkins service is hosted ? In short is there any way from client side to ensure cleanup the cache – Albatross Jan 09 '23 at 17:50
  • The way I achieved it was using git command. One must be sure what tag conventions is being used and is it really the case of duplicate tags. In other words the tag config may be duplicated in such case the current build config needs to be adjusted to have correct tag. This was helpful in deleting local and remote tags : https://devconnected.com/how-to-delete-local-and-remote-tags-on-git/ – Albatross Jan 09 '23 at 20:04
  • @Albatross - you can in fact do this via the script console, once you are there you have access as the user running the JVM to that machine https://www.jenkins.io/doc/book/managing/script-console/ – Sean Jan 20 '23 at 20:36