gyorgyabraham
gyorgyabraham

Reputation: 2608

Jenkins, git, submodules with custom URL (SSH)

Problem is simple: the main git repository can be accessed by Jenkins with ssh://ci_ro@server (works well), but I have submodules whose URL is different: ssh://server (without defining some user, this is to allow developers to work with this repo and its submodules). I am definitely not allowed (and frankly don't want to) commit CI - specific .gitmodule files (this would break developer repos), so don't even mention it please. So Jenkins can pull the main repo but instantly fails with:

Caused by: hudson.plugins.git.GitException: Command "git submodule update --init --recursive" returned status code 1: Cloning into blah/blah...
Host key verification failed.
fatal: The remote end hung up unexpectedly
Clone of 'ssh://server:someport/blah/blah...' into submodule path 'blah/blah' failed

My question: is it possible to tell Jenkins to use ssh://ci_ro@server... URL prefix for submodules instead of the configured ones in .gitmodules? Or any other workarounds, plugins, or hacks available? I looked through the job options and didn't find any useful option.

UPDATE

Thanks for all the help guys. The resolution was to allow the 'jenkins' system user to pull from the specific ssh server/port with git.

Upvotes: 2

Views: 4165

Answers (4)

gyorgyabraham
gyorgyabraham

Reputation: 2608

The resolution was to allow the system user running Jenkins to pull with SSH from the specified hosts/ports.

Upvotes: 3

richo
richo

Reputation: 8999

In your build step, do a

git submodule init

then recurse through the submodules and adjust their remotes, this isn't right but the script I used when my github username changed was:

#!/bin/sh
git remote -v | grep richoH | while read name url type; do
    newurl=`echo $url | sed -e "s/richoH/richo/"`
    git remote set-url $name $newurl
done

Then do a git submodule update, which I don't believe interferes with the remotes. This is untested but I believe sound.

Upvotes: 0

Sirex
Sirex

Reputation: 305

Try to change /etc/ssh/ssh_config on your build server:

    StrictHostKeyChecking no

Upvotes: 0

malenkiy_scot
malenkiy_scot

Reputation: 16615

You can always do it manually from a shell build step.

Upvotes: 1

Related Questions