我正在尝试将自动标记创建集成到我的bitbucket管道中 所以基本上我有一个bash脚本:
#!/bin/bash
# retrieve branch name
BRANCH_NAME=$(git branch | sed -n '/\* /s///p')
# remove prefix release
REGEXP_RELEASE="release\/"
VERSION_BRANCH=$(echo "$BRANCH_NAME" | sed "s/$REGEXP_RELEASE//")
echo "Current version branch is $VERSION_BRANCH"
# retrieve the last commit on the branch
VERSION=$(git describe --tags --match=$VERSION_BRANCH* --abbrev=0)
# split into array
VERSION_BITS=(${VERSION//./ })
#get number parts and increase last one by 1
VNUM1=${VERSION_BITS[0]}
VNUM2=${VERSION_BITS[1]}
VNUM3=${VERSION_BITS[2]}
VNUM3=$((VNUM3+1))
#create new tag
NEW_TAG="$VNUM1.$VNUM2.$VNUM3"
echo "Updating $VERSION to $NEW_TAG"
#get current hash and see if it already has a tag
GIT_COMMIT=`git rev-parse HEAD`
NEEDS_TAG=`git describe --contains $GIT_COMMIT`
#only tag if no tag already (would be better if the git describe command above could have a silent option)
if [ -z "$NEEDS_TAG" ]; then
echo "Tagged with $NEW_TAG (Ignoring fatal:cannot describe - this means commit is untagged) "
git tag $NEW_TAG
git push --tags
else
echo "Already a tag on this commit"
fi
然后是我的管道:
# This is a sample build configuration for Java (Maven).
# Check our guides at https://confluence.atlassian.com/x/zd-5Mw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: maven:3.3.9
pipelines:
default:
- step:
caches:
- maven
script: # Modify the commands below to build your repository.
- mvn clean package -Denv=uat
branches:
master:
- step:
caches:
- maven
script: # Modify the commands below to build your repository.
- mvn clean package -Denv=uat
- chmod +x tag.sh
- ./tag.sh
但是当管道尝试推送标签时,我收到错误:
./tag.sh<1s
+ ./tag.sh
Current version branch is master
Updating master-1.0.2 to master-1.0.3fatal: cannot describe '493bf0b1aef120879af57e25d63dde24ad0c7de2'
Tagged with master-1.0.3 (Ignoring fatal:cannot describe - this means commit is untagged)
Warning: Permanently added the RSA host key for IP address '104.192.143.3' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.
所以我不喜欢&#39;理解为什么我得到这个问题以及如何解决它。 我看过https://confluence.atlassian.com/bitbucket/use-ssh-keys-in-bitbucket-pipelines-847452940.html 但我不明白,因为我没有访问管道远程。随着IP的变化,我无法将其添加为已知主机。 有没有办法推动我正在执行构建的回购?
由于已找到标签并且克隆了回购,这意味着我当然可以推动。
答案 0 :(得分:0)
REPO不包含对您的公共SSH密钥的引用,或者正在运行管道的Docker映像包含repo在其authorized_keys文件中不知道的SSH密钥。
确保: - Docker上的SSH密钥Bitbucket管道映像存在且正确 - 检查哪些密钥有权访问bitbucket存储库,以确保授予正确的公钥访问权限。
该错误通常是SSH密钥不匹配的问题。我已经多次碰到它了。
要检查的其他事项: - 如果配置了公钥,请确保使用CAT命令(如果在nix上运行),因为编辑器的复制/粘贴不可靠。 - 如果您从其他地方复制/粘贴,请检查以确保
上的公钥