Skip to content

[ISSUE]: Azure pipelines always provides -no-branch- as prerelease label although branch is recognized #4534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks done
MTomBosch opened this issue May 6, 2025 · 0 comments

Comments

@MTomBosch
Copy link

MTomBosch commented May 6, 2025

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

GitVersion package

GitVersion.Tool

GitVersion version

6.3.0

Operating system

Linux

What are you seeing?

When I am running the Gitversion tool in my Azure pipeline I am always getting -no-branch- as prerelease label/tag on a develop branch. It is somehow related to the fact that Azure pipelines always checks out in detached head mode.

Strangely I can see in the logs that the branch was properly identified:
INFO [25-05-06 16:39:55:38] Branch from build environment: refs/heads/develop

Interestingly the previously used version of the tool (5.8.1) was providing the "develop" branch configuration "label" value when running on the exact same commit. We would like to get this behaviour back.

Any idea what is going wrong in my configuration?

I am pasting my config:

assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: ''
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
no-bump-message: '\+semver:\s?(none|skip)'
tag-pre-release-weight: 60000
commit-date-format: yyyy-MM-dd
merge-message-formats:
  tfs: "^Merged (?:PR (?<PullRequestNumber>\\d+)): Merge '?(?<SourceBranch>[^']+)'? (in)?(to) (?<TargetBranch>.+)"
update-build-number: true
semantic-version-format: Strict
strategies:
- Fallback
- ConfiguredNextVersion
- MergeMessage
- TaggedCommit
- TrackReleaseBranches
- VersionInBranchName
branches:
  develop:
    mode: ContinuousDelivery
    label: develop
    increment: Minor
    prevent-increment:
      of-merged-branch: false
    track-merge-target: true
    regex: ^(refs/heads/)?develop$
    source-branches: []
    is-source-branch-for: []
    tracks-release-branches: true
    is-release-branch: false
    is-main-branch: false
    pre-release-weight: 0
  main:
    mode: ContinuousDeployment
    label: ''
    increment: Patch
    prevent-increment:
      of-merged-branch: true
    track-merge-target: false
    regex: ^(refs/heads/)?master$|^(refs/heads/)?main$
    source-branches:
    - develop
    - release
    - hotfix
    is-source-branch-for: []
    tracks-release-branches: false
    is-release-branch: false
    is-main-branch: true
    pre-release-weight: 55000
  release:
    mode: ManualDeployment
    label: rc
    increment: None
    prevent-increment:
      of-merged-branch: true
    track-merge-target: false
    regex: ^(refs/heads/)?releases?[/-](?<BranchName>.+)
    source-branches:
    - develop
    - main
    - support
    - release
    is-source-branch-for: []
    tracks-release-branches: false
    is-release-branch: true
    is-main-branch: false
    pre-release-weight: 30000
  feature:
    mode: ManualDeployment
    label: '{BranchName}'
    increment: Inherit
    prevent-increment:
      of-merged-branch: false
    track-merge-target: false
    regex: ^(refs/heads/)?features?[/-](?<BranchName>.+)
    source-branches:
    - develop
    - main
    - release
    - feature
    - support
    - hotfix
    is-source-branch-for: []
    is-release-branch: false
    is-main-branch: false
    pre-release-weight: 30000
  pull-request:
    mode: ManualDeployment
    label: PullRequest{Number}
    increment: Inherit
    prevent-increment:
      of-merged-branch: false
    track-merge-target: false
    regex: ^(refs/)?(pull-requests|pull|pr|pullrequest)[/-](?<Number>\d*)
    source-branches:
    - develop
    - main
    - release
    - feature
    - support
    - hotfix
    tracks-release-branches: false
    is-source-branch-for: []
    is-release-branch: false
    is-main-branch: false
    pre-release-weight: 30000
  hotfix:
    mode: ManualDeployment
    label: beta
    increment: Patch
    prevent-increment:
      of-merged-branch: true
    track-merge-target: false
    regex: ^(refs/heads/)?hotfix(es)?[/-](?<BranchName>.+)
    source-branches:
    - develop
    - main
    - support
    tracks-release-branches: false
    is-source-branch-for: []
    is-release-branch: true
    is-main-branch: false
    pre-release-weight: 30000
  support:
    mode: ContinuousDeployment
    label: ''
    increment: Patch
    prevent-increment:
      of-merged-branch: true
    track-merge-target: false
    regex: ^(refs/heads/)?support[/-](?<BranchName>.+)
    source-branches:
    - main
    - pull-request
    - feature
    - hotfix
    is-source-branch-for: []
    tracks-release-branches: false
    is-release-branch: false
    is-main-branch: true
    pre-release-weight: 55000
ignore:
  sha: []
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
prevent-increment:
  of-merged-branch: false
  when-branch-merged: false
  when-current-commit-tagged: true
track-merge-target: false
track-merge-message: true
commit-message-incrementing: Enabled
regex: ''
source-branches: []
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: false

What is expected?

To get "develop" as "PreReleaseLabel" since the branch name is given via env var BUILD_SOURCEBRANCH.

Steps to Reproduce

#$1 is repo name
#$2 is branch name
#$3 is commit sha1

git init
git remote add origin https://[email protected]/my-org/${1}
git sparse-checkout disable
git config gc.auto 0
git config core.longpaths true
git fetch --force --tags --prune --prune-tags --progress --no-recurse-submodules origin --depth=1  +${3}:refs/remotes/origin/${3}
git fetch --force --tags --prune --prune-tags --progress --no-recurse-submodules origin --depth=1  +${3}
git checkout --progress --force refs/remotes/origin/$3
git submodule sync --recursive
git submodule update --init --force --depth=1 --recursive

log "Unshallowing Git repository"
git fetch --unshallow --no-recurse-submodules

# These env vars are set by Azure pipelines and are used by the gitversion tool. To recognize
# that it is running in a pipeline the TF_BUILD env var is used. The tool then uses the value of BUILD_SOURCEBRANCH to determine
# the branch name.
export TF_BUILD=True
export BUILD_SOURCEBRANCH=refs/heads/$2
export BUILD_BUILDNUMBER=123456
CURR_DIR=$(pwd)
COMMON_CLI_ARGS="/nonormalize /nocache /config "${ROOT_DIR}/GitVersion.yml""

set -x
"${ROOT_DIR}/dotnet-gitversion" "$CURR_DIR" $COMMON_CLI_ARGS /output file /outputfile "${ROOT_DIR}/semver.json" /verbosity Verbose /l "${ROOT_DIR}/semver.log"
set +x

RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).

@MTomBosch MTomBosch changed the title [ISSUE]: Azure pipelines always provides -no-branch- as prerelease label although Branch is recognized [ISSUE]: Azure pipelines always provides -no-branch- as prerelease label although branch is recognized May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant