uncleBounty
uncleBounty

Reputation: 783

How to setup git ssh connection on dockerized jenkins

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 :

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.

Upvotes: 0

Views: 3476

Answers (1)

BigGinDaHouse
BigGinDaHouse

Reputation: 1366

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.

Upvotes: 1

Related Questions