I am trying to setup a jenkins pipeline for my IaC code validation, for this I'd like jenkins to clone a gitlab (hosted) repository, for this purpose I setup a credential using username / key type, i used a jenkins user + a generated rsa key (same key on master and slave for simplicity).
When logged in the master or slave I can git clone using the following command and result :
root@jenkins-slave-1 [~]: su - jenkins jenkins@jenkins-slave-1:~$ cd /tmp/ jenkins@jenkins-slave-1:/tmp$ git clone email@example.com:salt/salt_states.git Cloning into 'salt_states'... remote: Enumerating objects: 1177, done. remote: Counting objects: 100% (1177/1177), done. remote: Compressing objects: 100% (483/483), done. remote: Total 1177 (delta 676), reused 1153 (delta 665) Receiving objects: 100% (1177/1177), 1.64 MiB | 0 bytes/s, done. Resolving deltas: 100% (676/676), done. jenkins@jenkins-slave-1:/tmp$
I can see the correct entry in auth log on gitlab instance, the one saying that a pubkey authentication was accepted.
BUT, when I run the pipeline (that is using the same credentials), it fails with this message :
Cloning the remote Git repository Honoring refspec on initial clone Cloning repository firstname.lastname@example.org:salt/salt_states.git > git init /home/jenkins/workspace/salt_build_test # timeout=10 Fetching upstream changes from email@example.com:salt/salt_states.git > git --version # timeout=10 using GIT_SSH to set credentials jenkins user's key (same key on master and slave(s)) > git fetch --tags --progress -- firstname.lastname@example.org:salt/salt_states.git +refs/remotes/origin/dev # timeout=20 ERROR: Error cloning remote repo 'origin' hudson.plugins.git.GitException: Command "git fetch --tags --progress -- email@example.com:salt/salt_states.git +refs/remotes/origin/dev" returned status code 128: stdout: stderr: Permission denied, please try again. Permission denied, please try again. Permission denied (publickey,password). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
The gitlab auth log is showing that the authentication tried to use a password auth mode, not a pubkey. ...
Oct 8 11:49:23 l-gitlab1 sshd: Failed password for git from 172.27.200.46 port 56750 ssh2 Oct 8 11:49:23 l-gitlab1 sshd: Connection closed by 172.27.200.46 port 56750 [preauth]
Any ideas about what I am doing wrong ?
[Edit] I added a screenshot as my explanation are not very clear :(