Azure DevOps Pipeline | Git Shallow Fetch

Problem Space

I have been recently working on building a new Yaml pipeline in Azure DevOps and wished to use the GitVersion Task, however, upon running the pipeline the task failed with the following error:

ERROR [../../.. ..:..:..:..] An unexpected error occurred:
System.NullReferenceException: Object reference not set to an instance of an object.

After some digging and a conversation with one of my colleagues, it turns out there has been a change on Azure DevOps pipelines. By default now when a pipeline is created, the ‘Get SourcesShallow fetch setting is enabled and set to a depth of 1.

The Shallow fetch setting if enabled will limit how far back in source history to download. Effectively using the following git command git fetch --depth=n.

This in turn causes the error seen above as the GitVersion task requires the whole repo branching model to calculate the SEMVER version.

Switching off Shallow Fetch

To switch off Shallow Fetch if using a Yaml pipeline:

  1. Edit your Pipeline.
  2. Selecting the ellipsis button, select Triggers.
  3. Navigate to the Yaml tab, and select Get Sources.
  4. There is a setting near the very bottom called Shallow fetch, switch the setting off and save.

For the original version of this post see Andrew Wilson's personal blog at Azure DevOps Pipeline | Git Shallow Fetch