Search code examples
gitjenkinssshssh-keys

Pushing git tag to ssh protocol type link failes in jenkins


I have a repo: https://github.com/Elydasian/gatling-example

I have a pipeline in jenkins ready, that checks out that repo, and after some building and whatnot, I want to tag the branch.

I made a "SSH Username with private key" credentials and added it to my jenkins pipeline Now, I am finished doing what I needed with it (I checkout the project)

Now I need to be able to TAG it. For that, I have done the following lines:

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

Then, it throws an error:

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.

Can you help me?


Solution

  • You need to make sure the right key is read.

    From your last question, that what sh 'GIT_SSH_COMMAND = "ssh -i $key"' was for in the withCredentials step.

    In your case, try git -c core.sshCommand='ssh -Tv' push origin TAG_NAME instead of just git push, in order to see what key it is trying to use.


    The OP Elydasian adds in the comments:

    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.