Skip to content

[Bug] BUILD_SOURCEBRANCH is assumed to be relevant #3316

@TheConstructor

Description

@TheConstructor

In Azure DevOps (Server) the environment variable BUILD_SOURCEBRANCH will contain the branch of the repository that triggered the build (see documentation for Build.SourceBranch). For multi-repository builds there is no relation to the self ("main") repository, but

public override string? GetCurrentBranch(bool usingDynamicRepos) => Environment.GetEnvironmentVariable("BUILD_SOURCEBRANCH");
uses the value of the environment variable without verifying.

Expected Behavior

The variable should not be used in multi-repository builds, as it causes incorrect versions.

Actual Behavior

We build the dev-branch of our repo, but GitVersion thinks it should provide a version for main, as that is the branch in another repository, that triggered the build

Possible Fix

For us it would likely help to have a switch to disable the AzurePipelines-handling. It may be possible to use System.PullRequest.SourceBranch/System.PullRequest.TargetBranch when set, but even then GitVersion could be called for another repo/sub-module

Steps to Reproduce

  1. Set-up a multi-repository build in Azure DevOps (Server) -> https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops
  2. Define a trigger on one of the other repositories on at leas one branch named different from the default-branch of the repository containing the build-definition
  3. Commit to the other repository into the branch you defined the trigger for
  4. A build will run and BUILD_SOURCEBRANCH is set to the name of the branch in the other repository

Context

We use GitVersion to version our documentation and want to update the development-docs whenever a commit is pushed. The branch in the docs-repo is dev, while the branch-name in other repos might be master. In this case a non-pre-release-version is generated

Your Environment

Azure DevOps Server 2020 Update 1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions