0
votes

There is like 3000 ways to setup authentification between jenkins and gitlab and i'm pretty confused. What I want to do is pretty trivial : Checkout from a gitlab branch, build with maven, create a docker image, push it into a registry

What I did :

  • Install gitlab plugins into jenkins
  • Setup API Token between gitlab and jenkins (Test SUCCESS)
  • Setup webhook between gitlab and jenkins (OK, my job if called for any push on git repo)
  • Add SSH PUBLIC credentials into Jenkins : id_rsa.pub content from the server that contains the jenkins docker container (with admin user)

My pipeline first stage :

node {
deleteDir()
def mvnHome
def pom
stage('Checkout SCM') {
  git branch: 'develop', credentialsId: 'xxxxxxxxxxxxxxx', url: '[email protected]:blablabla/blablablabla.git'
  mvnHome = tool 'M3'
  pom = readMavenPom file: 'pom.xml'}

Error :

ERROR: Error cloning remote repo 'origin' hudson.plugins.git.GitException: Command "git fetch --tags --progress [email protected]:blablabla/blablablabla.git +refs/heads/:refs/remotes/origin/" returned status code 128: stdout: stderr: Permission denied (publickey). fatal: Could not read from remote repository.

1

1 Answers

1
votes

you have to configure key pairs in following way

supposingly you have your public ssh key in gitlab (if not add it) in your docker env though to the user that is used for jenkins add private key

for testing, ssh to docker env from your local and execute same command as Jenkins is doing:

git fetch --tags --progress [email protected]:blablabla/blablablabla.git +refs/heads/:refs/remotes/origin/

Also, please take a pic here - https://www.blazemeter.com/blog/how-integrate-docker-jenkins , hope it will give yu more insights.