Answers: <p>The Gitlab plugin requires an auth token, you're trying to use an SSH key.</p>
  
  <p><a href="https://github.com/jenkinsci/gitlab-plugin#global-plugin-configuration" rel="nofollow noreferrer">https://github.com/jenkinsci/gitlab-plugin#global-plugin-configuration</a></p>
  
  <p>"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."</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-10-08T15:59:28.167Z
Answers: Thanks, but i am not using the gitlab plugin, iam just trying to setup the scm/git in a pipeline setup
Answers: Pier
Answers: CC BY-SA 4.0
Answers: 2019-10-08T16:59:44.423Z
Answers: I would take a look at: https://stackoverflow.com/questions/16721629/jenkins-returned-status-code-128-with-github
Answers: casey vega
Answers: CC BY-SA 4.0
Answers: 2019-10-08T15:55:24.580Z
Answers: 2019-10-08T15:55:24.580Z
Answers: casey vega
Body: <p>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).</p>
  
  <p>When logged in the master or slave I can git clone using the following command and result :</p>
  
  <pre><code>root@jenkins-slave-1 [~]: su - jenkins
  jenkins@jenkins-slave-1:~$ cd /tmp/
  jenkins@jenkins-slave-1:/tmp$ git clone git@l-gitlab1.domain: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$ 
  
  </code></pre>
  
  <p>I can see the correct entry in auth log on gitlab instance, the one saying that a pubkey authentication was accepted.</p>
  
  <p>BUT, when I run the pipeline (that is using the same credentials), it fails with this message :</p>
  
  <pre><code>Cloning the remote Git repository
  Honoring refspec on initial clone
  Cloning repository git@l-gitlab1.domain:salt/salt_states.git
   &gt; git init /home/jenkins/workspace/salt_build_test # timeout=10
  Fetching upstream changes from git@l-gitlab1.domain:salt/salt_states.git
   &gt; git --version # timeout=10
  using GIT_SSH to set credentials jenkins user's key (same key on master and slave(s))
   &gt; git fetch --tags --progress -- git@l-gitlab1.domain: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 -- git@l-gitlab1.domain: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.
  </code></pre>
  
  <p>The gitlab auth log is showing that the authentication tried to use a password auth mode, not a pubkey. ...</p>
  
  <pre><code>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]
  </code></pre>
  
  <p>Any ideas about what I am doing wrong ?</p>
  
  <p>The error:
  <a href="https://i.sstatic.net/5sbwF.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/5sbwF.png" alt="enter image description here"></a></p>
  
  <p>[Edit]
  I added a screenshot as my explanation are not very clear :(</p>
  
Comments: CC BY-SA 4.0
Comments: 2019-10-08T14:27:06.517Z
Comments: Where is your pipeline code? Can you post the particular section where you are cloning the repository?
Comments: Preston Martin
Comments: CC BY-SA 4.0
Comments: 2019-10-08T15:39:03.677Z
Comments: 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)
Comments: Pier
Comments: CC BY-SA 4.0
Comments: 2019-10-08T17:43:47.940Z
Comments: 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...
Comments: Preston Martin
Comments: CC BY-SA 4.0
Comments: 2019-10-08T18:04:44.003Z
Comments: I am using the git scm plugin... but not the gitlab plugin
Comments: Pier
Tags: <jenkins><jenkins-pipeline><git>
Title: jenkins credentials not used as expected when cloning git repo
UserDisplayName: Pier
ThreadText: # jenkins credentials not used as expected when cloning git repo
  
  (Asked by: username_0 on 2019-10-08)
  
  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 git@l-gitlab1.domain: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 git@l-gitlab1.domain:salt/salt_states.git
   > git init /home/jenkins/workspace/salt_build_test # timeout=10
  Fetching upstream changes from git@l-gitlab1.domain: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 -- git@l-gitlab1.domain: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 -- git@l-gitlab1.domain: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](https://i.sstatic.net/5sbwF.png)](https://i.sstatic.net/5sbwF.png)
  
  [Edit]
  I added a screenshot as my explanation are not very clear :(
  
  **Tags:** jenkins, jenkins-pipeline, git
  
  > **Comments:**
  > **username_1**: Where is your pipeline code? Can you post the particular section where you are cloning the repository?  
  > **username_0**: 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)  
  > **username_1**: 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...  
  > **username_0**: I am using the git scm plugin... but not the gitlab plugin  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-10-08. Score: 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."
  
  > **Comments:**
  > **username_0**: Thanks, but i am not using the gitlab plugin, iam just trying to setup the scm/git in a pipeline setup  
  > **username_2**: I would take a look at: https://stackoverflow.com/questions/16721629/jenkins-returned-status-code-128-with-github  
  
  ---
  
  