将标签推送到 Stash 以在 Jenkins 中成功构建失败,代码 128 和错误 "Insufficient permissions"

Push tag to Stash for successfull build in Jenkins fails with code 128 and error "Insufficient permissions"

我想为 Jenkins 的每个成功构建推送代码修订标签 CI。

我的工作看起来如何

  1. 我有 "Source Code Management" 设置以在表单

    中使用 git

    1.1 存储库 URL : ssh://git@:7999//.git

    1.2 凭据:我的 ssh 名称/我的 ssh 密钥

    1.2.1 我使用Credentials plugin来存储名称和密钥

    1.3 名称:repoName

    1.4 存储库查看器:stash

    1.4.1 URL : http://:7990/projects//repos/

    1.5 作为附加行为,我有 "Clean before checkout" 选项

  2. 我有 post 构建步骤 "Git publisher"

    2.1 "Push Only If Build Succeeds" 选中

    2.2 "Tag to push" $BUILD_NUMBER

    2.3 "Target remote name" repoName(如我在说明中阅读的 1.3 步骤中设置成功构建代码标记)

我的代码已成功签出(通过 repo 克隆),已构建但作业因错误将标签推送到 repo 失败

 > /usr/bin/git tag -l 176 # timeout=10
 > /usr/bin/git tag -a -f -m Jenkins Git plugin tagging with 176 176 # timeout=10
Pushing tag 176 to repo repoName
using GIT_SSH to set credentials 
 > /usr/bin/git --version # timeout=10
 > /usr/bin/git -c core.askpass=true push ssh://git@<repo url>:7999/<project>/<repo>.git 176
ERROR: Failed to push tag 176 to repoName
hudson.plugins.git.GitException: Command "/usr/bin/git -c core.askpass=true push ssh://git@<repo url>:7999/<project>/<repo>.git 176" returned status code 128:
stdout: 
stderr: fatal: remote error: Insufficient permissions
You do not have permission to push to the repository <repo> in project <project>
fatal: Could not read from remote repository.

但同样 using GIT_SSH to set credentials 在作业开始时成功调用设置权限以回购克隆。

我在网上发现了一些 posts 和这里描述相同问题的问题,但我不清楚为什么我应该在从成功回购开始的工作中为 git 手动设置 ssh 密钥使用我的密钥进行克隆。

有谁能帮我指出如何告诉 git 将与用于 repo 克隆的密钥相同的密钥用于标签推送?

更新 1:我登录构建(从)机器,检查标签并找到所有标签

user@machine:~/workspace/Build$ git tag
1.0
1.0.1
1.1
1.2
1.2.1
1.3
1.3.1
1.3.2
1.3.3
164
165
166
167
168
169
170
171
172
173
174
175
176
177
180
181
182
183
184
2.0.0
2.1.0
2.2.0
2.2.1
2.3.0
2.3.1
jenkins-Build-166
jenkins-Build-169
jenkins-Build-170
user@machine:~/workspace/Build$

我试着推动它

sk@mgc-cranberry:~/workspace/CranberryPackageBuild$ git push origin 184
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
sk@mgc-cranberry:~/workspace/CranberryPackageBuild$

我也尝试了命令 /usr/bin/git -c core.askpass=true push ssh://git@<repo url>:7999/<project>/<repo>.git 176 并得到了相同的结果。

更新 2:我还发现问题 Git Publisher does not use Credentials 描述了相同的行为,但我的版本比问题已修复的版本更新。我认为问题出在我的配置中,但目前我无法确定其根本原因。所以,欢迎提出想法!

所以,我仍然不明白为什么 Git Publisher 插件在作业开始时不从克隆中获取授权。

看起来 git 推送命令使用的任何帐户(SSH 密钥)都不能写入存储库。您需要检查并相应地进行更改(通过在 Stash 中授予该密钥访问权限,或使用已经具有访问权限的密钥)。

我首先要验证您提供的密钥是否是 git 命令所使用的密钥。我怀疑如果您在 git 回购插件的职权范围之外编写自己的自定义 git 命令,则不会自动获取。