GitVersion: [ISSUE]: GitVersion is undefined in Azure DevOps on PR builds using GitTools 3.1.1
Prerequisites
- I have written a descriptive issue title
- I have searched issues to ensure it has not already been reported
GitVersion package
AzureDevops task
GitVersion version
6.0.5
Operating system
Linux
What are you seeing?
I recently updated to the new GitTools tasks from UseGitVersion@5 along with new config and have had no issues building code for approximately a week. When I opened a pull request today, the automatic build triggered by our PR requirement failed stating that GitVersion is undefined. Looking at the logs, I can see that the checkout process is working as expected with all our most recent commits to the repository and we automatically tag every commit into master/main branches so history shouldn’t be an issue. Any suggestions/workarounds would be appreciated.
What is expected?
Pull request builds should behave the same way when using GitTools in Azure DevOps.
Steps to Reproduce
# azure-pipelines.yaml job template
parameters:
- name: DependsOn
type: object
default: []
jobs:
- job: AdoBuildNumber
dependsOn: ${{ parameters.DependsOn }}
pool:
name: 'ubuntu-latest'
steps:
- checkout: self
fetchDepth: 0
- task: gitversion/setup@3.1.1
displayName: Install GitVersion
inputs:
versionSpec: '6.0.x'
- task: gitversion/execute@3.1.1
displayName: Determine Version
name: git_version # variable to use in subsequent steps
inputs:
overrideConfig: |
update-build-number=false
- pwsh: |
$build_number = "$(git_version.majorMinorPatch)-$(git_version.preReleaseLabel)-$(git_version.buildMetaData)"
echo "##vso[build.updatebuildnumber]$($build_number)"
displayName: 'Set Build Number using GitVersion'
# GitVersion.yaml
workflow: GitHubFlow/v1
strategies:
- Mainline
assembly-versioning-format: '{MajorMinorPatch}-{PreReleaseLabel}-{BuildMetaData}'
RepositoryFixture Test
No response
Output log or link to your CI build (if appropriate).
Starting: Determine Version
==============================================================================
Task : Execute GitVersion Task
Description : Easy Semantic Versioning (https://semver.org) for projects using Git
Version : 3.1.1
Author : GitTools Contributors
Help : See the [documentation](https://gitversion.net/docs/) for help
==============================================================================
Running on: 'Azure Pipelines'
Disable Telemetry
Command: git -C /agent/_work/15/s rev-parse --is-shallow-repository
Command: /opt/hostedtoolcache/GitVersion.Tool/6.0.5/dotnet-gitversion /agent/_work/15/s /output json /l console /overrideconfig update-build-number=false
##[error]GitVersion output is not valid JSON
dotnet-gitversion Output:
-------------------
undefined
-------------------
undefined
Finishing: Determine Version
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 26 (7 by maintainers)
Commits related to this issue
- Switch to TrunkBased/preview1 https://github.com/GitTools/GitVersion/issues/4350 — committed to Project-MONAI/monai-deploy-security by mocsharp 2 years ago
- Release/1.0.1 (#89) * Bump Microsoft.NET.Test.Sdk from 17.4.0 to 17.4.1 Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.4.0 to 17.4.1. - [Release notes](https://github.co... — committed to Project-MONAI/monai-deploy-security by mocsharp 2 years ago
I’ve also encountered the same issue using the gitversion@3 tasks, however none of above solutions worked for me. Since some of the builds succeeded, I’ve assumed it has to be something with the installation itself. After digging into the logs, it seemed that gitversion/setup didn’t run as expected and installed the tool into another directory.
Running
ls $env:GITVERSION_PATHresulted in:which I’ve found is an Azure DevOps specification for installing tools (check following doc).
In order to handle this, I’ve configured my pipeline as follows:
The second step checks the installation path and adjusts it accordingly. As this is rather an ugly workaround, I’d assume it can be easily fixed.
Whenever a build previously failed, I’ve now get a log like:
Setting 'GITVERSION_PATH' to '/agent/_work/_tool/GitVersion.Tool/6.0.5/x64'Noticed the undefined as well in azure devops pipelines when using
workflow: TrunkBased/preview1Problem might be that “merge from master” feature is used to get latest from the trunk into the current feature, and potentially not using feature branch but accidental a different mistyped variant. (Thus hitting the ‘unknown’ configuration)However when it happens a rebase seems not succeed either so a full new branch is normally created with cherry picks from the one that experiences it. It might be most likely due to the following:
Hopefully https://github.com/GitTools/GitVersion/issues/4057 will get some attention for such weird cases, as trunkbased is really something simpler to use in most cases but the undefined is really a heavy blow when encountered
Thanks for the info! Changing the workflow did fix my issue.
I had a similar issue in my DevOps pipeline where this stopped working today (2025-01-13 - was working yesterday). In my case the issue was building a pipeline on a bugfix branch.
Here is the devops git version config that I am using:
I can confirm that changing the workflow fixed my issue, changing the GitVersion.yml as follows:
to
This thread has saved me some time, so thanks to all!
Please try the TrunkBased/preview1 workflow:
If you have a merge from main to your feature or hotfix branch then this can be a problem as well. You should know currently the feature to support multi mainline branches in the Mainline version strategy (#4057) is not implemented.
@DaveSkender I’m seeing
undefinedon thesetupstep everytime either way; don’t know whether the additional info is useful.@HHobeck From my end, exactly the same configuration will return different results in ADO depending on whether I use
UseGitVersion@5with the version set tov6.0.xorgitversion/execute@v3.1.1. The latter works when building locally or building a branch directly, but does not work when auto-building pull request branches; the former always works.It might be worth mentioning that ADO (and I believe GitHub Actions as well) automatically create a new branch including the current target branch and the changes in the source branch in the pull request before running any subsequent build steps. I’m not confident on whether that branch is of the target with the source merged in or of the source with the target merged in, but I suspect that this has something to do with GitVersion being unable to determine versioning.
Considering that this works as expected in v5 as well as the deprecated
UseGitVersion@5task, but not the newer task, I would expect this to be a bug on GitVerison’s side at this point.