Git submodules not updating in Jenkins build
Note that the Jenkins Git plugin 2.0 will have "advance submodule behaviors", which should ensure proper updates of the submodules:
As commented by vikramvi
:
Advanced sub-modules behavior
> "Path of the reference repo to use during submodule update
" against this field , add submodule git url.
Owen B mentions in the comments:
For the authentication issue, there's now a "Use credentials from default remote of parent repository" option
Seen here in JENKINS-20941:
Finally stumbled on a way to do this and it's simple.
The Issue:
The initial clone with credentials works fine but subsequent submodule
cloning fails with incorrect credentials.
- Automatic advanced sub-module cloning:
Source Code Management >> Additional Behaviours >> Advanced sub-modules behaviours
: results in credential error. git submodule update --init
in theExecute Shell
section also fails with credentials error.
The Solution:
I'm using jenkins-1.574
.
- Check the
Build Environment >> SSH Agent
box. - Select the correct credentials (probably the same as selected in
Source Code Management
section Update submodules in the
Execute Shell
sectiongit submodule sync git submodule update --init --recursive
Here's a screen shot
Are you aware that your Git repository always refers to a particular revision of a submodule? Jenkins is not going to automatically change the revision.
If you want to take a newer revision of the submodule into use, you have to do this in your local Git repository:
cd submoduledir
git pull
cd ..
git add submoduledir
git commit -m 'Updated to latest revision of submoduledir'
git push # Go and watch Jenkins build with the new revision of the submodule
When you do it like this, Jenkins will check out the exact same revision of the submodule during the build. Jenkins does not on its own decide which revision of the submodule to use. This is the fundamental difference between Git submodules and SVN externals.
You might want to read a good reference on submodules, e.g. http://progit.org/book/ch6-6.html.
This is covered in the Git Plugin documentation on the Jenkins site under the section: Recursive submodules.
excerptThe GIT plugin supports repositories with submodules which in turn have submodules themselves. This must be turned on though: in Job Configuration -> Section Source Code Management, Git -> Advanced Button (under Branches to build) -> Recursively update submodules.
Example
From the configuration screen of your job, in the Source Code Management section, pull the Add button down select "Advanced sub-modules behavior".
Then select "Recursively update submodules":