Question

The problem

I'm trying to build my application in Jenkins, and it is on a private repo on Github, also there's a private submodule.

I can clone the private repository in Jenkins by setting up it's credentials, but Jenkins can't clone the submodule, here's the output of a failed build:

Started by an SCM change
Building in workspace /var/lib/jenkins/jobs/Project/workspace
Fetching changes from the remote Git repository
Fetching upstream changes from git@github.com:user/repogit
using GIT_SSH to set credentials 
Checking out Revision 9cc99b67cc676d0ea8ccd489a8327f5c6dbb8d7f (origin/branch)
[workspace] $ /bin/sh -xe /tmp/hudson2710403018107019432.sh
+ git submodule update --init --recursive
Initialized empty Git repository in /var/lib/jenkins/jobs/repository/submodule/.git/
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly
Clone of 'git@github.com:user/submodule.git' into submodule path 'repository/submodule/' failed
Build step 'Execute shell' marked build as failure
Discard old builds...
#156 is removed because status FAILURE is not to be kept
Publishing Clover coverage report...
No Clover report will be published due to a Build Failure
Sending e-mails to: 
Finished: FAILURE

Here's what I've tried to do in Jenkins

  • Tried to set the Additional behavior "Advanced sub-module behavior", with no success.
  • Tried to set up a new step before running the tests with phpunit:

git submodule update --init --recursive

  • Tried to set a git repository on the project of my submodule too, not just the main repository that is being tested, no luck too.

All of them causes the error that says that Jenkins can't find the repository of the submodule.

Any ideas of how can I solve this?

(The username, paths and repositories are correct, I've just changed them to post here)

Was it helpful?

Solution

Solved. In my credential I was using a direct SSH key (option "Enter directly"), instead of putting into a file.

I've just put the keys (public and private) in ~/.ssh, and changed my credentials to the option "From the Jenkins master ~/.ssh".

The problem was that the submodule wasn't using the credential that I've specified to the main repository, it was trying to use the default ssh key (.ssh/id_rsa).

Another solution is to pass -i my_key to the git submodule step (only need this if your key isn't in the default path (~/.ssh/id_rsa) )

Also don't forget to give the correct permissions to your keys, in my case I had to:

chown apache ~/.ssh/id_rsa*
chmod 700 ~/.ssh/id_rsa*
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top