Skip to content

[Bug] Building from tag fails to produce correct version on Azure DevOps #2231

Closed
@alarobric

Description

@alarobric

Describe the bug

When building in Azure DevOps, recently we've been getting some strange version numbers from GitVersion. We follow ReleaseFlow, and it's mostly working for us normally. We do feature branches and merge to master. Every so often when we are ready to release to customers, we branch a release branch "release/ProdName/v6.9". Builds here look like "6.9.2-rc.220" until we decide to git tag, at which point we get 6.9.2 as expected.
Recently though, we've been getting builds like "6.10.0-tags-ProdName-v6-9-2.1+220" instead. We couldn't work out what was going on or what was causing. It seemed to only be affecting one product within the monorepo at first, and removing and recreating the release branch seemed to have fixed it.

We now see it again, but I've noticed today that it's tied to the build trigger. If I trigger a build on the branch release/ProdName/v6.9, where the latest commit is tagged "ProdName/v6.9.2", I'll get the expected result of a version 6.9.2. If instead I trigger a build on the tag, it builds the exact same commit but gives a version 6.10.0-tags-ProdName-v6-9-2.1+220

Expected Behavior

Version 6.9.2

Actual Behavior

Version 6.10.0-tags-ProdName-v6-9-2.1+220

Possible Fix

Found in the GitVersion source that the part "Branch from build environment: xxx" comes from the Azure Pipelines env variable BUILD_SOURCEBRANCH. In each build, the git checkout is actually the same, and specifies only the commit, no branches. On the tag one it's refs/tags/ProdName/v6.9.2 and this then results in "No branch configuration found for branch tags/ProdName/v6.9.2

My understanding is that a tag on a commit should always override any branch info, but that doesn't seem to be happening.

Steps to Reproduce

As above, trigger build from release branch, or from tag. In both cases the commit being built is the same, all steps are the same.
Agent parameters are same.
Git commands run by Azure DevOps are the same. Tag is present in both. Commit is the same.

Tag build says:
Git step title in Azure Devops is "Checkout RepoName@refs/tags/ProdName/v6.9.2 to s"
command used is >git checkout --progress --force 24257159c4cf9db433be7c50fa12b38d670834c2
sourceBranch=refs/tags/ProdName/v6.9.2
Finishing: Checkout RepoName@refs/tags/ProdName/v6.9.2 to s

Release branch build says:
Git step title in Azure Devops is "Checkout RepoName@release/ProdName/v6.9 to s"
command used is >git checkout --progress --force 24257159c4cf9db433be7c50fa12b38d670834c2
sourceBranch=refs/heads/release/ProdName/v6.9
Finishing: Checkout RepoName@release/ProdName/v6.9 to s

After the checkout step, a powershell script is run with following
"GitVersion.exe /output buildserver /nofetch"

Tag build produces this:

INFO [04/13/20 16:39:34:87] Branch from build environment: refs/tags/ProdName/v6.9.2
INFO [04/13/20 16:39:34:87] Begin: Normalizing git directory for branch 'refs/tags/ProdName/v6.9.2'
  INFO [04/13/20 16:39:34:91] One remote found (origin -> 'https://[email protected]/xxx/yyy/_git/yyy').
  INFO [04/13/20 16:39:34:91] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
  INFO [04/13/20 16:39:34:92] Creating local branch refs/heads/tags/ProdName/v6.9.2 pointing at 24257159c4cf9db433be7c50fa12b38d670834c2
...
...
INFO [04/13/20 16:39:39:75] HEAD points at branch 'refs/heads/tags/ProdName/v6.9.2'.
  INFO [04/13/20 16:39:39:76] End: Normalizing git directory for branch 'refs/tags/ProdName/v6.9.2' (Took: 4,885.91ms)
  INFO [04/13/20 16:39:39:76] Project root is: D:\a\1\s\
  INFO [04/13/20 16:39:39:76] DotGit directory is: D:\a\1\s\.git
  INFO [04/13/20 16:39:39:81] Begin: Loading version variables from disk cache
    INFO [04/13/20 16:39:39:82] Cache file D:\a\1\s\.git\gitversion_cache\CBCB265AD7F0967CA735B87FE6496A4CBD84218D.yml not found.
  INFO [04/13/20 16:39:39:82] End: Loading version variables from disk cache (Took: 3.11ms)
  INFO [04/13/20 16:39:39:97] Using latest commit on specified branch
  INFO [04/13/20 16:39:39:99] No branch configuration found for branch tags/ProdName/v6.9.2, falling back to default configuration
  INFO [04/13/20 16:39:39:99] Begin: Attempting to inherit branch configuration from parent branch
    INFO [04/13/20 16:39:40:02] HEAD is merge commit, this is likely a pull request using master as base

Release branch build produces this:

INFO [04/13/20 19:26:26:84] Branch from build environment: refs/heads/release/ProdName/v6.9
INFO [04/13/20 19:26:26:84] Begin: Normalizing git directory for branch 'refs/heads/release/ProdName/v6.9'
  INFO [04/13/20 19:26:26:88] One remote found (origin -> 'https://[email protected]/xxx/yyy/_git/yyy').
  INFO [04/13/20 19:26:26:88] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
  INFO [04/13/20 19:26:26:90] Creating local branch refs/heads/release/ProdName/v6.9
...
INFO [04/13/20 19:26:32:23] HEAD points at branch 'refs/heads/release/ProdName/v6.9'.
  INFO [04/13/20 19:26:32:25] End: Normalizing git directory for branch 'refs/heads/release/ProdName/v6.9' (Took: 5,404.82ms)
  INFO [04/13/20 19:26:32:25] Project root is: D:\a\1\s\
  INFO [04/13/20 19:26:32:25] DotGit directory is: D:\a\1\s\.git
  INFO [04/13/20 19:26:32:30] Begin: Loading version variables from disk cache
    INFO [04/13/20 19:26:32:31] Cache file D:\a\1\s\.git\gitversion_cache\9BA9A688F479E76BB5CBBC3C4AD2917538E6D017.yml not found.
  INFO [04/13/20 19:26:32:31] End: Loading version variables from disk cache (Took: 3.57ms)
  INFO [04/13/20 19:26:32:46] Using latest commit on specified branch
  INFO [04/13/20 19:26:32:52] Running against branch: release/ProdName/v6.9 (24257159c4cf9db433be7c50fa12b38d670834c2)
  INFO [04/13/20 19:26:32:52] Current commit is tagged with version 6.9.2, version calculation is for metadata only.

I tried but can't reproduce this locally because it's tied to the buildserver code.
Branch from build environment: refs/tags/ProdName/v6.9.2 coming from the environment variables on Azure DevOps.

I'm looking at reproducing in a integration test, but not sure exactly how.

It is similar to issue #2206 but without timing or process discussion. Seems only related to Azure DevOps environment.

Context

When building in Azure DevOps, recently we've been getting some strange version numbers from GitVersion. We follow ReleaseFlow, and it's mostly working for us normally. We do feature branches and merge to master. Every so often when we are ready to release to customers, we branch a release branch "release/ProdName/v6.9". Builds here look like "6.9.2-rc.220" until we decide to git tag, at which point we get 6.9.2 as expected.
Recently though, we've been getting builds like "6.10.0-tags-ProdName-v6-9-2.1+220" instead. We couldn't work out what was going on or what was causing. It seemed to only be affecting one product within the monorepo at first, and removing and recreating the release branch seemed to have fixed it.

Your Environment

  • Version Used: ??
  • Operating System and version (Windows 10, Ubuntu 18.04): Windows - Azure Pipeline build agent
  • Link to your project: Private
  • Link to your CI build (if appropriate): Sorry, private

GitVersion.yml

next-version: 6.9.0
mode: ContinuousDeployment # Default: ContinuousDelivery
assembly-informational-format: '{FullSemVer}' # Default: {InformationalVersion}
tag-prefix: 'ProdName/[vV]'
branches: 
  master:
    regex: master
    mode: ContinuousDeployment
    tag: beta
    increment: Minor
    prevent-increment-of-merged-branch-version: true
    track-merge-target: false
    tracks-release-branches: true
    is-release-branch: false
  feature:
    regex: features?[/-]
    mode: ContinuousDeployment
    tag: useBranchName
    increment: Patch
    prevent-increment-of-merged-branch-version: true
    track-merge-target: true
    tracks-release-branches: true
    is-release-branch: false
  release:
    regex: releases?[/-]
    mode: ContinuousDeployment
    tag: rc
    increment: Patch
    prevent-increment-of-merged-branch-version: true
    track-merge-target: false
    tracks-release-branches: false
    is-release-branch: true
ignore:
  sha: []

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions