Bamboo fails to checkout tag: "error: pathspec 'tags/TAG' did not match any file(s) known to git"
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Bamboo fails to fetch/checkout a tag from a repository and throws "error: pathspec 'tags/<TAG>' did not match any file(s) known to git"
.
Environment
All Bamboo supported versions. Observed while connecting to a Bitbucket Server/Data Center repository.
Diagnosis
The following error can be seen in the build logs when trying to run a script to check out a specific tag after fetching the repository:
simple 13-May-2024 12:18:50 Checking out into /data/bamboo/bamboo-home/xml-data/build-dir/PROJ-PLAN-JOB1
[...]
simple 13-May-2024 12:18:57 Switched to a new branch 'develop'
[...]
simple 13-May-2024 12:18:57 Starting task of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'
command 13-May-2024 12:18:57 Beginning to execute external process for build '...'\n ... running command line: \n/usr/local/bamboo/bamboo-agent-home/temp/PROJ-PLAN-JOB1-BUILD_NUMBER-ScriptBuildTask-1108459876148053107.sh\n ... in: /data/bamboo/bamboo-home/xml-data/build-dir/PROJ-PLAN-JOB1\n
error 13-May-2024 12:18:57 + git fetch --all
error 13-May-2024 12:18:57 + git checkout tags/<TAG>
build 13-May-2024 12:18:57 Checking out tags/<TAG> tag ...
error 13-May-2024 12:18:57 error: pathspec 'tags/<TAG>' did not match any file(s) known to git
simple 13-May-2024 12:18:57 Failing task since return code of [/usr/local/bamboo/bamboo-agent-home/temp/PROJ-PLAN-JOB1-BUILD_NUMBER-ScriptBuildTask-1108459876148053107.sh] was 1 while expected 0
simple 13-May-2024 12:18:57 Finished task 'Build artifacts' with result: Failed
By getting more information of the branch the tag is associated to, you can see the tag is associated with a different branch than the one that was built.
- On a local copy of the repository that contains the TAG, run git fetch --all through the Command Line to fetch all the branches and tags from the repository.
- Run git rev-parse <TAG> to identify the commit associated with the tag.
- Finally, to list all branches (both local and remote) that contain the commit, use: git branch -a --contains HASH, replacing HASH with the actual commit hash you found in the step above.
You should see that the tag is associated with a different branch and doesn't have any links to the branch being built in Bamboo. In the example above, the branch being build was develop, while the tag is linked with master:
[command_line]$ git rev-parse TAG
COMMIT_ID
[command_line]$ git branch -a --contains COMMIT_ID
remotes/origin/HEAD -> origin/master
remotes/origin/master
Cause
Since the tag is associated with the master branch, and the build is running using the develop branch, the copy of the repository does not include the tags associated with branches other than develop. By default, Bamboo only checks out the branch of the repository being built – in this case, only the develop branch was checked out.
Solution
The solution consists of making sure the desired tag is part of the branch being built. E.g., if you want to checkout tag myTag when building the branch develop, the tag should be part of that branch.
Workaround
Another option is to enable Fetch whole repository: this results in Bamboo checking out all the branches in the repository, not the only one being built. By enabling it when running a "develop" branch build, the "master" branch would also checked out, which would make tags from other branches available.
Steps
Global linked repository:
- Bamboo administration > Linked repositories > Select the desired repository > Advanced options > Check "Fetch whole repository"
Plan level repository:
- Plan Configuration > Repositories > Edit > Advanced options > Check "Fetch whole repository"
Other scenarios
If the tag you're trying to checkout is part of the branch being built, there could be a mismatch or corruption in the repository cache. Please try on of the following:
Cache cleanup
Try cleaning up the cache of the affected repository: Git cache cleanup in Bamboo
- Bamboo Administration > Build Resources > Repository Settings > select the affected repository's cache and delete it.
git fetch command options
You can also try different variations of the git fetch command to fetch the tags:
git fetch
git fetch --all
git fetch --tags --all --force