1

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 protected]: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 [email protected]:salt/salt_states.git
 > git init /home/jenkins/workspace/salt_build_test # timeout=10
Fetching upstream changes from [email protected]: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 -- [email protected]: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 protected]: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[18490]: Failed password for git from 172.27.200.46 port 56750 ssh2
Oct  8 11:49:23 l-gitlab1 sshd[18490]: Connection closed by 172.27.200.46 port 56750 [preauth]

Any ideas about what I am doing wrong ?

The error: enter image description here

[Edit] I added a screenshot as my explanation are not very clear :(

4
  • 1
    Where is your pipeline code? Can you post the particular section where you are cloning the repository?
    – Preston Martin
    Commented Oct 8, 2019 at 14:27
  • I don't have pipeline code yet, this behaviour is seen when setting up the credential in pipeline "wizard" as well as when running the pipeline (which at this early point is only launching a Shell command, but this shell part is not even reached as the git clone fails)
    – Pier
    Commented Oct 8, 2019 at 15:39
  • Ok, what configuration or settings are you are using then? You say you are using a pipeline, but you don't have a template file? It's unclear to me how your Jenkins job/pipeline is setup if you aren't using declarative pipelines and you aren't using the git scm plugin...
    – Preston Martin
    Commented Oct 8, 2019 at 17:43
  • I am using the git scm plugin... but not the gitlab plugin
    – Pier
    Commented Oct 8, 2019 at 18:04

1 Answer 1

1

The Gitlab plugin requires an auth token, you're trying to use an SSH key.

https://github.com/jenkinsci/gitlab-plugin#global-plugin-configuration

"PLEASE NOTE: This auth configuration is only used for accessing the GitLab API for sending build status to GitLab. It is not used for cloning git repos. The credentials for cloning (usually SSH credentials) should be configured separately, in the git plugin."

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.