Jenkins Pipeline based on groovy : unable to push into git => Permission denied (publickey)
<p><strong>Jenkins Context</strong></p>

<p>Jenkins version : version 2.23<BR> 
I am trying to make a git push from a jenkins pipeline using a groovy script.
The goal is to create a tag in a stage and push it remotely on my git repo.
<BR><BR>
What is going wrong with my pipeline job configuration (cf below)?</p>

<p><strong>Problem</strong></p>

<p>I have an account with credentialsId that runs perfectly for the fetch and clone.
But I get the following error when I try to push my tags.</p>

<blockquote>
  <p>git push ssh://git.server:29418/AA/myrepo.git --tags
  Permission denied (publickey). fatal: Could not read from remote
  repository.</p>
</blockquote>

<p><strong>Credentials / SSH</strong> </p>

<p>Public key is correctly added into my git/gerrit server
<BR>
The account has "ALLOW" rights on gerrit :</p>

<p>Reference: refs/tags/*</p>

<ul>
<li>Create Reference</li>
<li>Forge Author Identity</li>
<li>Forge Committer Identity</li>
<li>Push</li>
<li>Push Annotated Tag</li>
<li>Push Signed Tag </li>
</ul>

<p><strong>Jenkins Pipeline : groovy script</strong></p>

<hr>

<pre><code>node {
    echo "=================="
    string workspace=pwd()
    sh ('ls -al $workspace')

    String credentialsId="aaa-bbb-ccc-ddd-eee"
    String  gitRepo="ssh://git.server:29418/AA/myrepo.git"

    // stage
    stage "Test Tag Push"

    git credentialsId: "${credentialsId}", url: "${gitRepo}"


    println "cmd = git tag "
    sh(script: 'git tag')

    tagName="MyTag"

    sh(script: "git tag -d $tagName")
    sh(script: "git tag $tagName")
    sh(script: 'git tag')
    println "git repo : ${gitRepo}"
    sh('git push ssh://git.server:29418/AA/myrepo.git --tags')
}
</code></pre>

<hr>

<p><strong>Console Output</strong></p>

<pre><code>&gt; Entering stage Test Tag Push
Proceeding
[Pipeline] git
 &gt; git rev-parse --is-inside-work-tree # timeout=10
 &gt; git config remote.origin.url ssh://git.server:29418/AA/myrepo.git # timeout=10
Fetching upstream changes from ssh://git.server:29418/AA/myrepo.git
 &gt; git --version # timeout=10
using GIT_SSH to set credentials aacloud user for gerrit connection
 &gt; git -c core.askpass=true fetch --tags --progress ssh://git.server:29418/AA/myrepo.git +refs/heads/*:refs/remotes/origin/*
 &gt; git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 &gt; git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 20fc371cf27bb57049e75a040f00986ab6a71473 (refs/remotes/origin/master)
 &gt; git config core.sparsecheckout # timeout=10
 &gt; git checkout -f 20fc371cf27bb57049e75a040f00986ab6a71473
 &gt; git branch -a -v --no-abbrev # timeout=10
 &gt; git branch -D master # timeout=10
 &gt; git checkout -b master 20fc371cf27bb57049e75a040f00986ab6a71473
 &gt; git rev-list 20fc371cf27bb57049e75a040f00986ab6a71473 # timeout=10
[Pipeline] echo
cmd = git tag 
[Pipeline] sh
[cockpit-pipeline-test-TC] Running shell script
+ git tag
MyTag
Tag001
tc001
tc002
[Pipeline] sh
[cockpit-pipeline-test-TC] Running shell script
+ git tag -d MyTag
Deleted tag 'MyTag' (was 20fc371)
[Pipeline] sh
[cockpit-pipeline-test-TC] Running shell script
+ git tag MyTag
[Pipeline] sh
[cockpit-pipeline-test-TC] Running shell script
+ git tag
MyTag
Tag001
tc001
tc002
[Pipeline] echo
git repo : ssh://git.server:29418/AA/myrepo.git
[Pipeline] sh
[cockpit-pipeline-test-TC] Running shell script
+ git push ssh://git.server:29418/AA/myrepo.git --tags
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 128
Finished: FAILURE
</code></pre>