Using Git submodules in (private) Azure DevOps repositories

I often use Git Submodules in my repositories, it’s a handy way to have external source code in your repo, without having to worry much about the external updates and source management (you can just checkout, pull etc as every normal git repo).

Often the external sources are hosted in public GitHub repos, without any need to authenticate.
You create .gitmodules file look like:†

[submodule "DbConnector"]
	path = DbConnector
	url = https://github.com/chaconinc/DbConnector

And with a few more command you are ready to go.

Lastly I wanted to use submodules between my private Azure DevOps repositories in the same Azure DevOps Project.
So I added the submodule with its full path, like:

[submodule "voyager-core"]
	path = voyager-core
	url = https://youruser@dev.azure.com/AzureDevOpsProject/DigitalPlatform/_git/voyager-core

But during the runs of my YAML Multi-Staged Pipelines (I love them!) I was getting the following error:

Cloning into '/ado/agent-03/15/s/voyager-core'...
fatal: could not read Password for 'https://youruser@dev.azure.com': terminal prompts disabled
##[debug]STDOUT/STDERR stream read finished.
fatal: clone of 'https://youruser@dev.azure.com/AzureDevOpsProject/DigitalPlatform/_git/voyager-core' into submodule path '/ado/agent-03/15/s/voyager-core' failed
Failed to clone 'voyager-core' a second time, aborting
##[debug]STDOUT/STDERR stream read finished.
##[debug]Finished process 1549 with exit code 1, and elapsed time 00:00:00.3789123.
##[error]Git submodule update failed with exit code: 1

After reading the Azure DevOps documentation I noticed this sentence: “Added by using a URL relative to the main repository”
So I changed the path of the submodule relative to the main repository, like:

[submodule "voyager-core"]
	path = voyager-core
	url = ../voyager-core

After this change, everything was working fine!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑