在 jenkins 中将 git 标记推送到 ssh 协议类型 link 失败

Pushing git tag to ssh protocol type link failes in jenkins

我有一个仓库:https://github.com/Elydasian/gatling-example

我在 jenkins 中准备了一个管道,它检查那个 repo,在一些构建之后等等,我想标记分支。

我创建了一个“带私钥的 SSH 用户名”凭证并将其添加到我的 jenkins 管道中 现在,我完成了我需要的工作(我检查了项目)

现在我需要能够标记它。 为此,我做了以下几行:

git tag TAG_NAME
git remote set-url --push origin git@github.com:Elydasian/gatling-example.git 
git push origin TAG_NAME

然后,它抛出一个错误:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

你能帮帮我吗?

您需要确保读取了正确的密钥。

来自你的 , that what sh 'GIT_SSH_COMMAND = "ssh -i $key"' was for in the withCredentials step.

对于您的情况,请尝试 git -c core.sshCommand='ssh -Tv' push origin TAG_NAME 而不是 git push,以查看它正在尝试使用的密钥。


OP Elydasian adds in :

At the end, the problem was not the code, but server permissions, as my pipeline was running multiple commands on multiple servers (only one of them had my credentials SSH key).

The solution was to split my pipeline to work only on one server.