Sean
Sean

Reputation: 8797

Why is Jenkins getting Authentication Failed error for git submodule update?

I have a Jenkins job that pulls from a BitBucket repo that was working fine, and still is. However, I've added a submodule and Jenkins is choking on that. Here is a clip from the Jenkins console output:

FATAL: Command "C:\Program Files (x86)\Git\cmd\git.exe submodule update" returned status code 1: stdout: Cloning into 'submodules/my.repo'...

stderr: fatal: Authentication failed

I'm using an ssh key which I added to my deployment keys for the main repo in BitBucket. And that's always worked. I added the same key to my submodule repo's deployment keys. Can anyone tell me why authentication is failing?

Upvotes: 10

Views: 7754

Answers (6)

I am really sorry for necro posting. But for the future visitors. If you are pulling the Main repo (that repo contains a submodule) using ssh, if your .gitmodule file's url set to [https:]//xxxxxx/foo.git jenkins won't be able authenticate and build will be failed. So you should update your url under the .gitmodule file with ssh url.

If you are face any authentication problems please go to [http://]yourjenkins.com -> manage jenkins -> security and find "Git Host Key Verification Configuration" and be sure that it is set to Accept First connection

Here is the visual guide

and if you still facing the issue please go to /var/jenkins_home/workspace/YOUR_JOB_NAME and check for pulled repo

Upvotes: 0

Mark Waite
Mark Waite

Reputation: 1500

Versions of the Jenkins git plugin prior to 3.0.0 did not support submodule authentication. Submodule authentication using the same credentials and protocol as the parent repository are now supported with the Jenkins git plugin. Support was added in the 10 Sep 2016 release of Jenkins git plugin 3.0.0.

The submodule configuration portion of the job definition page ("Additional Behaviours" > "Advanced Sub-modules Behaviours") includes a checkbox "Use credentials from default remote of parent repository". Check that box and the credentials from the parent repository will be used for the submodules.

Note: the repository cloning protocols must be the same (ssh or https) for the parent repository and all the submodules, otherwise the parent credentials can't be used with the submodule repository.

Upvotes: 6

Emre Akcan
Emre Akcan

Reputation: 1160

Additional to above answers, I realized that I'm using https urls of the submodules in my main repo, so I had to change my submodule url's https to ssh in main git repo.

Upvotes: 0

Johnny Cage
Johnny Cage

Reputation: 6380

git config --global credential.helper wincred

https://help.github.com/articles/caching-your-github-password-in-git/#platform-windows

Upvotes: 0

Destroyica
Destroyica

Reputation: 4267

I faced this issue, with Jenkins Slave (executed as Windows Service). I solved it by deploying Jenkins SSH key in the .ssh directory of the SYSTEM user:

C:\Windows\SysWOW64\config\systemprofile\.ssh\

SYSTEM home directory varies depending on OS version and setup. To identify it just echo env. var. %USERPROFILE%

Upvotes: 0

Johnny Chen
Johnny Chen

Reputation: 2070

Try to copy the /.shh folder into your Jenkins home directory.

Upvotes: 0

Related Questions