What you should think about when running Azure Pipelines with Git and submodules

When you work with Azure (DevOps) Pipelines and use Azure Repos (Git) in combination with Git submodules, then there are a few things that you need to take into account if you want to use those submodules in your build pipeline(s) an if you want those pipelines to successfully 😉

I'm writing this here because we have had a few cases where a build would fail due to one or more missing files, but without any sort of indication that this due to the fact that a submodule was not explicitly loaded in the build context.

In the logs, this would typically manifest itself like this:

1C:\Program Files\dotnet\sdk\5.0.203\NuGet.targets(290,5): error MSB3202: The project file 
2"E:\<AgentWorkDir>\<submodulefolder>\<blahblahblah>.csproj" was not found. 
3##[error]The NuGet packages failed to restore.

The path will typically be shown and this is all the info that you will get. It is then up to you to figure out that the folder points to a submodule and that you need to specify on build level that the submodule needs to be checked out too when starting the build.

This can be done in the settings of the build pipeline. (Which you can get to via the "triggers" menu when you are editing your build and then by clicking on the "YAML" tab and then on get sources.)

Typically, you will see something like what is shown in the image below:

Please notice that "Checkout submodules" is not checked!

Checking the "Checkout submodules" box, adds another dropdown, which asks you how you want to load your submodules. In the screenshot below, I selected the one with the most impact (of the 2 available options), even when we only had one submodule in this case...

That should be it and if you save your pipeline, then you should be able to launch your build pipeline and this time without issues!

There is, one point to note however: When creating new Azure DevOps Project, there are a few pipeline settings/permissions that need to be set to make this possible. They are very restrictive (for a reason) and you need to explicitly allow your build pipeline to do the actions needed for loading other repo's. I Wrote about this in the post: Dealing with error TF401019 when using submodules in Azure Pipelines

That's it! I hope this helps you when you encounter this issue!

comments powered by Disqus