Bamboo fails to checkout tag: "error: pathspec 'tags/TAG' did not match any file(s) known to git"
プラットフォームについて: Data Center - この記事は、Data Center プラットフォームのアトラシアン製品に適用されます。
このナレッジベース記事は製品の Data Center バージョン用に作成されています。Data Center 固有ではない機能の Data Center ナレッジベースは、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。
*Fisheye および Crucible は除く
要約
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"
.
環境
All Bamboo supported versions. Observed while connecting to a Bitbucket Server/Data Center repository.
診断
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
原因
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.
ソリューション
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.
回避策
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.
手順
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