Skip to content
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

[ISSUE]: GitVersion is undefined in Azure DevOps on PR builds using GitTools 3.1.1 #4350

Open
2 tasks done
officeSpacePirate opened this issue Dec 20, 2024 · 24 comments
Open
2 tasks done

Comments

@officeSpacePirate
Copy link

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/[email protected]
    displayName: Install GitVersion
    inputs:
      versionSpec: '6.0.x'

  - task: gitversion/[email protected]
    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
@ChaosYoda
Copy link

I am running into the same issue, it seems to help to throw all the old agents away and try again. Seems the default Azure pipeline behavior is to do a detached head checkout, even if you set the fetchDepth: 0

@DaveSkender
Copy link

DaveSkender commented Dec 30, 2024

This occurs on GitHub Actions too, so it's not likely an Azure DevOps specific issue.

I think in the end though the real problem here is that it takes a PhD to understand all the configuration options and all the different tool implementation options. I haven't solved all my problems, but am making progress by running the underlying dotnet-gitversion commands, which seem to produce better debugging information about your setup.

# GitHub Action workflow, for troubleshooting
    runs-on: ubuntu-latest
    steps:

      - name: Checkout source
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Check GitVersion config presence
        run: cat src/gitversion.yml

      - name: Setup GitVersion Tool
        run: dotnet tool install --global GitVersion.Tool --version 6.0.5

      - name: Show GitVersion config
        run: dotnet-gitversion /showconfig /config src/gitversion.yml

        # for comparison, this is the same as the "execute" pre-built step
      - name: Show GitVersion config (with Json output)
        run: dotnet-gitversion /output json /l console /config src/gitversion.yml

The pre-defined gittools/actions/gitversion setup and execute tasks mostly look like they're just executing these dotnet commands anyway, but they don't seem to handle errors well or report problems with configs, just BSD types of feedback.

Pre-defined GitHub Action tasks and output, for comparison
      - name: Setup GitVersion
        uses: gittools/actions/gitversion/setup@v3
        with:
          versionSpec: "6.0.5"

      - name: Determine version
        id: gitversion
        uses: gittools/actions/gitversion/execute@v3
        with:
          useConfigFile: true
          configFilePath: src/gitversion.yml
          updateAssemblyInfo: true
Run gittools/actions/gitversion/[email protected]
  with:
    versionSpec: 6.0.5
    includePrerelease: false
    ignoreFailedSources: false
    preferLatestVersion: false
Running on: 'GitHub Actions'
Disable Telemetry
--------------------------
Acquiring GitVersion.Tool for version spec: 6.0.5
--------------------------
Looking for local tool [email protected]
Directory /opt/hostedtoolcache/GitVersion.Tool/6.0.5 not found
Command: dotnet tool install GitVersion.Tool --tool-path /home/runner/work/_temp/2cddf8c4-6e0e-4e25-b7b9-551db7b265ae --version 6.0.5
--------------------------
GitVersion.Tool version: 6.0.5 installed.
--------------------------
Prepending /opt/hostedtoolcache/GitVersion.Tool/6.0.5 to PATH
Updated PATH: /opt/hostedtoolcache/GitVersion.Tool/6.0.5:/snap/bin:/home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Set GITVERSION_PATH to /opt/hostedtoolcache/GitVersion.Tool/6.0.5
dotnet-gitversion Output:
-------------------
undefined
-------------------
gittools/actions/gitversion/[email protected]
  with:
    useConfigFile: true
    targetPath: /home/runner/work/MyRepoName/MyRepoName
    configFilePath: src/gitversion.yml
    disableCache: false
    disableNormalization: false
    disableShallowCloneCheck: false
    updateAssemblyInfo: false
  env:
    DOTNET_CLI_TELEMETRY_OPTOUT: true
    DOTNET_NOLOGO: true
    DOTNET_ROOT: ../lib/dotnet
    GITVERSION_PATH: /opt/hostedtoolcache/GitVersion.Tool/6.0.[5](https://github.com/MyOrgName/MyRepoName/actions/runs/12541632759/job/34970406692#step:5:5)
Running on: 'GitHub Actions'
Disable Telemetry
Command: git -C /home/runner/work/MyRepoName/MyRepoName rev-parse --is-shallow-repository
Command: /opt/hostedtoolcache/GitVersion.Tool/[6](https://github.com/MyOrgName/MyRepoName/actions/runs/12541632759/job/34970406692#step:5:6).0.5/dotnet-gitversion /home/runner/work/MyRepoName/MyRepoName /output json /l console /config src/gitversion.yml
Error: GitVersion output is not valid JSON
dotnet-gitversion Output:
-------------------
undefined
-------------------

@HHobeck
Copy link
Contributor

HHobeck commented Dec 30, 2024

Can you reproduce it locally and provide steps to reproduce? The undefined value is a strange result which I see the first time. Is this error related to the configuration (Mainline version strategy in combination with GitHubFlow/v1)? What happen if you just use the GitHubFlow/v1 or TrunkBased/preview1 workflow template without customization? Is it related to your repository? What happen if you use a vanilla git repository?

@officeSpacePirate
Copy link
Author

@HHobeck I tried going back to the GitVersion task using v6.0.x to see whether it would be a viable workaround. The build still fails, but it looks like GitVersion is failing to calculate on a PR branch. Here's the error from my build output:

ERROR [24-12-30 14:02:27:54] An unexpected error occurred:
System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at GitVersion.VersionCalculation.MainlineVersionStrategy.GetCommitsWasBranchedFrom(IBranch branch, IBranch[] excludedBranches) in /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 299
   at GitVersion.VersionCalculation.MainlineVersionStrategy.<>c__DisplayClass13_0.<IterateOverCommitsRecursive>b__0() in /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 143
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at GitVersion.VersionCalculation.MainlineVersionStrategy.IterateOverCommitsRecursive(IEnumerable`1 commitsInReverseOrder, MainlineIteration iteration, IBranch targetBranch, String targetLabel, ILookup`2 taggedSemanticVersions, HashSet`1 traversedCommits) in /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 150
   at GitVersion.VersionCalculation.MainlineVersionStrategy.IterateOverCommitsRecursive(IEnumerable`1 commitsInReverseOrder, MainlineIteration iteration, IBranch targetBranch, String targetLabel, ILookup`2 taggedSemanticVersions, HashSet`1 traversedCommits) in /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 258
   at GitVersion.VersionCalculation.MainlineVersionStrategy.GetBaseVersions(EffectiveBranchConfiguration configuration)+MoveNext() in /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 105
   at GitVersion.VersionCalculation.NextVersionCalculator.<>c__DisplayClass14_0.<<GetNextVersions>g__GetNextVersionsInternal|0>d.MoveNext() in /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 264
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at GitVersion.VersionCalculation.NextVersionCalculator.GetNextVersions(IBranch branch, IGitVersionConfiguration configuration) in /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 239
   at GitVersion.VersionCalculation.NextVersionCalculator.CalculateNextVersion(IBranch branch, IGitVersionConfiguration configuration) in /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 158
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 53
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in /_/src/GitVersion.Core/Core/GitVersionCalculateTool.cs:line 45
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in /_/src/GitVersion.App/GitVersionExecutor.cs:line 66

Just to reiterate, the configuration I've mentioned so far works as expected locally and when building a branch directly in ADO; the failure only occurs for pull request builds. I'll try a few different configurations and get back to you if I have any luck.

@officeSpacePirate
Copy link
Author

officeSpacePirate commented Dec 30, 2024

@HHobeck Alright, I tried a few different configurations and it looks like Mainline is the problem. Hopefully this makes sense based on the error output in my previous comment. The configuration in my original post works if you simply remove the strategies property. I think this points to the issue being between v5.x and v6.x rather than the GitVersion task or ADO/GitHub.

The problem is, I'm now unsure how to get my versioning structured the way I expect coming from v5. Is this a bug on GitVersion's end or do I need to change my configuration? Here's what we have on our master branch today using v5 in a .NET repository:

mode: Mainline
# not sure why we are overriding this; I added an override in the new config to have a property on the GitVersion object that was unique without +'s for Docker/ECR
assembly-informational-format: '{NuGetVersionV2}+{Sha}'

@HHobeck
Copy link
Contributor

HHobeck commented Dec 30, 2024

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
Copy link

This occurs on GitHub Actions too ...

For my situation, I was able to determine that the issue is with the built-in task:

# what the built-in gittools/actions/gitversion task does
# produces error: Cannot find the .git directory
dotnet-gitversion /output json /l console /config src/gitversion.yml
# works as expected
dotnet-gitversion -output json -l console -config src/gitversion.yml

In other words, the built-in task is using / argument syntax that does seem to work. And just an FYI, with these commands dotnet-gitversion and dotnet gitversion both work, but gitversion alone does not.

@officeSpacePirate
Copy link
Author

@HHobeck I was able to get a successful build after changing to TrunkBased, though it looks like the GitVersion property values change pretty significantly so I'll have to make sure I understand the expectations there.

On a different note, it appears that the build only works when using the old GitVersion task. When I change back to the new way of doing things, I'm getting undefined as mentioned above. It's possible that @DaveSkender has already determined the root issue to that though.

@officeSpacePirate
Copy link
Author

officeSpacePirate commented Dec 30, 2024

In case anyone else is running into this issue, here's my current workaround:

# GitVersion.yaml
workflow: TrunkBased/preview1
strategies:
  - Mainline
assembly-versioning-format: '{MajorMinorPatch}-{PreReleaseLabel}-{CommitsSinceVersionSource}'
# 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: UseGitVersion@5
    displayName: Use GitVersion
    inputs:
      versionSpec: '6.0.x'

  - pwsh: |
      $build_number = "$(GitVersion.majorMinorPatch)-$(GitVersion.preReleaseLabel)-$(GitVersion.commitsSinceVersionSource)"
      echo "##vso[build.updatebuildnumber]$($build_number)"
    displayName: 'Set Build Number using GitVersion'

The use of CommitsSinceVersionSource is to avoid +'s because they are invalid characters in versions for container registries. It looks like using TrunkBased doesn't include one now, but GitHubFlow does so I'm simply being explicit. Another note is that the BuildMetaData property is null when using TrunkBased, so I decided on the one that seemed to make the most sense.

@HHobeck
Copy link
Contributor

HHobeck commented Dec 30, 2024

The use of CommitsSinceVersionSource is to avoid +'s because they are invalid characters in versions for container registries. It looks like using TrunkBased doesn't include one now, but GitHubFlow does so I'm simply being explicit. Another note is that the BuildMetaData property is null when using TrunkBased, so I decided on the one that seemed to make the most sense.

Please see following Q/A:

@officeSpacePirate
Copy link
Author

The use of CommitsSinceVersionSource is to avoid +'s because they are invalid characters in versions for container registries. It looks like using TrunkBased doesn't include one now, but GitHubFlow does so I'm simply being explicit. Another note is that the BuildMetaData property is null when using TrunkBased, so I decided on the one that seemed to make the most sense.

Please see following Q/A:

@HHobeck That's actually what I tried first, but it is not unique between builds/commits. When automatically publishing packages, I essentially need the FullSemVer, but without a + in it. Since BuildMetaData is null when using TrunkBased, I opted for CommitsSinceVersionSource. Another option would be to use ShortSha if character length is not an issue.

@HHobeck
Copy link
Contributor

HHobeck commented Dec 30, 2024

@HHobeck That's actually what I tried first, but it is not unique between builds/commits. When automatically publishing packages, I essentially need the FullSemVer, but without a + in it. Since BuildMetaData is null when using TrunkBased, I opted for CommitsSinceVersionSource. Another option would be to use ShortSha if character length is not an issue.

I don't understand what you are writing. If you use the Continues Deployment mode then the pre-release number will be incremented on every commit. I think you have a misunderstanding about how the modes are working. Even though in the TrunkBased/preview1 workflow you can customize it (the pre-release number will be always 1 on the main branch because of the Mainline version strategy algorithm).

@ChaosYoda
Copy link

I think what he is trying to say is that Continuous Deployment mode will keep incrementing but with a +<number> at the end. This is not compatible with Nuget versioning, even though the number is accepted nuget drops off the +<number> and it leaves you with the same version as the previous build, where v5 had the padded commit number which could be used. The problem is mainly that the +234 or whatever postfix is not compatible.

@officeSpacePirate
Copy link
Author

I don't understand what you are writing. If you use the Continues Deployment mode then the pre-release number will be incremented on every commit. I think you have a misunderstanding about how the modes are working. Even though in the TrunkBased/preview1 workflow you can customize it (the pre-release number will be always 1 on the main branch because of the Mainline version strategy algorithm).

Are you saying that the default mode is ManualDeployment? I was under the impression that it was ContinuousDelivery, which is what I want.

To be specific, the repo I'm updating is currently set to v5 and the following:

# complete GitVersion.yaml
mode: Mainline
assembly-informational-format: '{NuGetVersionV2}+{Sha}'

Which results in FullSemVer as {Major}.{Minor}.{Patch}-{EscapedBranchName}.{PreReleaseNumber or CommitsSinceVersionSource}


I updated to v6 and tried:

# GitVersion.yaml
workflow: GitHubFlow/v1
strategies:
  - Mainline

Which results in FullSemVer as {Major}.{Minor}.{Patch}-{EscapedBranchName}.{PreReleaseNumber}+{BuildMetaData or CommitsSinceVersionSource}. In this case, PreReleaseNumber is always 1 no matter how many commits I have on a non-main branch. I also can't have the + for building or publishing containers, so I added the override to use the AssemblySemVer as my default. This configuration is also the one that works locally and when building a branch directly in ADO, but does not work when building pull requests.


I then opened this GitHub issue and tried your suggestion:

# GitVersion.yaml
workflow: TrunkBased/preview1
strategies:
  - Mainline

Which results in FullSemVer as {Major}.{Minor}.{Patch}-{EscapedBranchName}.{PreReleaseNumber or CommitsSinceVersionSource}. In this case, BuildMetaData is always null, but the FullSemVer doesn't have a + in it causing an issue either. As I mentioned above, I only kept the custom versioning because of the differences between GitHubFlow / TrunkBased and I wanted to be explicit. This also resolves the issue I'm having with PR builds so long as I use UseGitVersion@5 instead of gitversion/[email protected] for now.

@HHobeck
Copy link
Contributor

HHobeck commented Dec 30, 2024

Which results in FullSemVer as {Major}.{Minor}.{Patch}-{EscapedBranchName}.{PreReleaseNumber}+{BuildMetaData or CommitsSinceVersionSource}. In this case, PreReleaseNumber is always 1 no matter how many commits I have on a non-main branch. I also can't have the + for building or publishing containers, so I added the override to use the AssemblySemVer as my default. This configuration is also the one that works locally and when building a branch directly in ADO, but does not work when building pull requests.

It depends on what branch you are building and what template you are using. If you take a look to e.g. the GitHubFlow/v1 workflow template:

You see the ManualDeployment mode for branches:

  • release
  • feature
  • unknown

and ContinuousDelivery mode for branches:

  • main
  • pull-request

@HHobeck
Copy link
Contributor

HHobeck commented Jan 2, 2025

On a different note, it appears that the build only works when using the old GitVersion task. When I change back to the new way of doing things, I'm getting undefined as mentioned above. It's possible that @DaveSkender has already determined the root issue to that though.

I guess we have mixed up thinks here. @arturcic do you have an idea what the problem might be? Are all informationen present in this ticket to reproduce it? Because it seem to me a infrastructure problem, I cannot help.

@DaveSkender
Copy link

DaveSkender commented Jan 2, 2025

Here's ^^ a bit of a repro, but generally it's working with my use case, despite the persistent UNDEFINED runner console output.

@officeSpacePirate
Copy link
Author

officeSpacePirate commented Jan 2, 2025

Here's ^^ a bit of a repro, but generally it's working with my use case, despite the persistent UNDEFINED runner console output.

@DaveSkender I'm seeing undefined on the setup step everytime either way; don't know whether the additional info is useful.


On a different note, it appears that the build only works when using the old GitVersion task. When I change back to the new way of doing things, I'm getting undefined as mentioned above. It's possible that @DaveSkender has already determined the root issue to that though.

I guess we have mixed up thinks here. @arturcic do you have an idea what the problem might be? Are all informationen present in this ticket to reproduce it? Because it seem to me a infrastrucutre problem, I cannot help.

@HHobeck From my end, exactly the same configuration will return different results in ADO depending on whether I use UseGitVersion@5 with the version set to v6.0.x or gitversion/[email protected]. 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.

# my entire GitVersion.yaml configuration for a .NET code repository
workflow: TrunkBased/preview1
strategies:
  - Mainline
assembly-versioning-format: '{MajorMinorPatch}-{PreReleaseLabel}-{CommitsSinceVersionSource}'

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@5 task, but not the newer task, I would expect this to be a bug on GitVerison's side at this point.

@officeSpacePirate
Copy link
Author

@HHobeck I noticed that the Mainline strategy is included in the default config for TrunkBased and decided to test through some additional scenarios. It looks like using the default config works in ADO with the gitversion/[email protected] as expected, so I've gone ahead and removed the two properties I was providing. Based on the build output and the GitVersion docs however, I still have no idea why it worked or why my previous configuration failed with only gitversion/[email protected] and not UseGitVersion@5. It's also worth noting that gitversion/[email protected] has a version constraint that does not allow for v6.1.1 (latest) to be used, but it works without issue if I use UseGitVersion@5.

Since I am completed unblocked, feel free to close this ticket out. If you have time to explain what was causing the issue, I would really appreciate any extra insights for future development. Thanks for all the time you've already given me.

@d-barker
Copy link

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.

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.

Running on: 'Azure Pipelines'
Disable Telemetry
Command: git -C /home/vsts/work/1/s rev-parse --is-shallow-repository
Command: /opt/hostedtoolcache/GitVersion.Tool/6.0.5/dotnet-gitversion /home/vsts/work/1/s /output json /l console /config /home/vsts/work/1/s/GitVersion.yml
##[warning]Free memory is lower than 5%; Currently used: 95.69%
##[warning]Free memory is lower than 5%; Currently used: 95.69%
##[warning]Free memory is lower than 5%; Currently used: 95.69%
##[warning]Free memory is lower than 5%; Currently used: 95.69%
##[warning]Free memory is lower than 5%; Currently used: 95.69%
##[warning]Free memory is lower than 5%; Currently used: 95.69%
##[warning]Free memory is lower than 5%; Currently used: 95.69%
##[warning]Free memory is lower than 5%; Currently used: 95.69%
##[warning]Free memory is lower than 5%; Currently used: 95.69%
##[error]GitVersion output is not valid JSON
dotnet-gitversion Output:
-------------------
undefined
-------------------
undefined
Finishing: Create Version

Here is the devops git version config that I am using:

  - task: gitversion/setup@3
    inputs:
      versionSpec: "6.0.5"
      includePrerelease: false

  - task: gitversion/execute@3
    displayName: "Create Version"
    inputs:
      useConfigFile: true
      configFilePath: "GitVersion.yml"

I can confirm that changing the workflow fixed my issue, changing the GitVersion.yml as follows:

workflow: GitHubFlow/v1

to

workflow: TrunkBased/preview1

This thread has saved me some time, so thanks to all!

@Duranom
Copy link

Duranom commented Jan 29, 2025

Noticed the undefined as well in azure devops pipelines when using workflow: TrunkBased/preview1
Problem 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:

Please try the TrunkBased/preview1 workflow:

* [Mainline in 6.0.0 with default configuration values throws #4236 (reply in thread)](https://github.com/GitTools/GitVersion/discussions/4236#discussioncomment-10785593)

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.

Hopefully #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

@ThibaultLesuisse
Copy link

I had the same error (output was undefined) recently and by adding this step before the gitversion I got it fixed for our organization. I have no clue as to why or how so take this with a grain of salt:

git -C /agent/_work/1/s/repo config --unset extensions.worktreeConfig

@pfaustinom1
Copy link

I'm facing the same issue.

I've tried to see the differences between @0 and @3 version, as I was using @0 previously and everything was working correctly:

trigger:
  branches:
   include:
     - master

pool:
  vmImage: windows-2022

steps:
- checkout: self
  fetchDepth: 0

- task: gitversion/setup@0
  inputs:
    versionSpec: '5.12.0'
  displayName: 'GitVersion > setup'

- task: gitversion/execute@0
  displayName: 'Run > gitversion execute (Windows)'

- task: gitversion/setup@3
  inputs:
    versionSpec: '5.12.0'
  displayName: 'GitVersion > setup'

- task: gitversion/execute@3
  displayName: 'Run > gitversion execute (Windows)'

Logs from @0:

Starting: GitVersion > setup
==============================================================================
Task         : Setup GitVersion Task
Description  : Easy Semantic Versioning (https://semver.org/) for projects using Git
Version      : 0.13.6
Author       : GitTools Contributors
Help         : See the [documentation](https://gitversion.net/docs/) for help
==============================================================================
Agent: 'Azure Pipelines'

--------------------------
Acquiring GitVersion.Tool version spec: 5.12.0
--------------------------
Command: dotnet tool install GitVersion.Tool --tool-path D:\a\_temp --version 5.12.0
"C:\Program Files\dotnet\dotnet.exe" tool install GitVersion.Tool --tool-path D:\a\_temp --version 5.12.0
You can invoke the tool using the following command: dotnet-gitversion
Tool 'gitversion.tool' (version '5.12.0') was successfully installed.
Caching tool: GitVersion.Tool 5.12.0 x64
--------------------------
GitVersion.Tool version: 5.12.0 installed.
--------------------------
Prepending PATH environment variable with directory: C:\hostedtoolcache\windows\GitVersion.Tool\5.12.0\x64
Finishing: GitVersion > setup
2025-02-12T09:23:29.0228203Z ##[section]Starting: Run > gitversion execute (Windows)
2025-02-12T09:23:29.0235325Z ==============================================================================
2025-02-12T09:23:29.0235507Z Task         : Execute GitVersion Task
2025-02-12T09:23:29.0235595Z Description  : Easy Semantic Versioning (https://semver.org) for projects using Git
2025-02-12T09:23:29.0235761Z Version      : 0.13.6
2025-02-12T09:23:29.0235834Z Author       : GitTools Contributors
2025-02-12T09:23:29.0235919Z Help         : See the [documentation](https://gitversion.net/docs/) for help
2025-02-12T09:23:29.0236057Z ==============================================================================
2025-02-12T09:23:29.4987313Z Agent: 'Azure Pipelines'
2025-02-12T09:23:29.4996542Z Command: git rev-parse --is-shallow-repository
2025-02-12T09:23:29.5001674Z [command]C:\agents\4.251.0\externals\git\cmd\git.exe rev-parse --is-shallow-repository
2025-02-12T09:23:29.5021641Z fatal: not a git repository (or any of the parent directories): .git
2025-02-12T09:23:29.5048413Z Command: dotnet-gitversion D:/a/1/s /output json /output buildserver
2025-02-12T09:23:29.5059410Z [command]C:\hostedtoolcache\windows\GitVersion.Tool\5.12.0\x64\dotnet-gitversion.exe D:/a/1/s /output json /output buildserver
2025-02-12T09:23:31.3326472Z INFO [02/12/25 9:23:29:92] Working directory: D:/a/1/s
2025-02-12T09:23:31.3327394Z INFO [02/12/25 9:23:30:07] Project root is: D:\a\1\s\
2025-02-12T09:23:31.3327771Z INFO [02/12/25 9:23:30:07] DotGit directory is: D:\a\1\s\.git
2025-02-12T09:23:31.3328011Z INFO [02/12/25 9:23:30:07] Branch from build environment: refs/heads/master
2025-02-12T09:23:31.3328441Z INFO [02/12/25 9:23:30:08] Begin: Normalizing git directory for branch 'refs/heads/master'
2025-02-12T09:23:31.3329052Z   INFO [02/12/25 9:23:30:23] One remote found (origin -> 'https://xxx.visualstudio.com/xxx/_git/xxxr').
2025-02-12T09:23:31.3329438Z   INFO [02/12/25 9:23:30:24] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
2025-02-12T09:23:31.3329753Z   INFO [02/12/25 9:23:30:24] Creating local branch master
2025-02-12T09:23:31.3329995Z   INFO [02/12/25 9:23:30:33] HEAD points at branch 'refs/heads/master'.
2025-02-12T09:23:31.3330298Z   INFO [02/12/25 9:23:30:35] End: Normalizing git directory for branch 'refs/heads/master' (Took: 259.12ms)
2025-02-12T09:23:31.3330580Z   INFO [02/12/25 9:23:30:36] Begin: Loading version variables from disk cache
2025-02-12T09:23:31.3330881Z     INFO [02/12/25 9:23:30:36] Cache file D:\a\1\s\.git\gitversion_cache\9AF505F732B9C1A9A32527F6D2EFB5868BDFD6AB.yml not found.
2025-02-12T09:23:31.3331195Z   INFO [02/12/25 9:23:30:36] End: Loading version variables from disk cache (Took: 0.69ms)
2025-02-12T09:23:31.3331462Z   INFO [02/12/25 9:23:30:37] Using latest commit on specified branch
2025-02-12T09:23:31.3331734Z   INFO [02/12/25 9:23:30:41] Running against branch: master (02286cb Update azure-pipelines.yml for Azure Pipelines)
2025-02-12T09:23:31.3332144Z   INFO [02/12/25 9:23:30:41] Begin: Calculating base versions
2025-02-12T09:23:31.3332433Z     INFO [02/12/25 9:23:30:45] Fallback base version: 0.1.0 with commit count source e6a03f45b59bf6e704044de70830948529dc054a
2025-02-12T09:23:31.3332785Z     INFO [02/12/25 9:23:30:54] Found commit [02286cb Update azure-pipelines.yml for Azure Pipelines] matching merge message format: Default
2025-02-12T09:23:31.3333141Z     INFO [02/12/25 9:23:30:54] Found commit [02286cb Update azure-pipelines.yml for Azure Pipelines] matching merge message format: Default
2025-02-12T09:23:31.3333496Z     INFO [02/12/25 9:23:30:54] Found commit [02286cb Update azure-pipelines.yml for Azure Pipelines] matching merge message format: Default
2025-02-12T09:23:31.3333852Z     INFO [02/12/25 9:23:30:54] Found commit [02286cb Update azure-pipelines.yml for Azure Pipelines] matching merge message format: Default
2025-02-12T09:23:31.3334208Z     INFO [02/12/25 9:23:30:54] Found commit [02286cb Update azure-pipelines.yml for Azure Pipelines] matching merge message format: Default
2025-02-12T09:23:31.3355869Z     INFO [02/12/25 9:23:30:54] Merge message 'Merge branch 'release/2.4.0'': 2.4.0 with commit count source f3f7eb475dbafaf31f9081d1b9c37a1673be7112
2025-02-12T09:23:31.3356271Z     INFO [02/12/25 9:23:30:54] Merge message 'Merge branch 'release/2.3.0'': 2.3.0 with commit count source 70ff5ee645baa3ec74bc9c4e64f0b70fd7d10727
2025-02-12T09:23:31.3356649Z     INFO [02/12/25 9:23:30:54] Merge message 'Merge branch 'release/2.2.0'': 2.2.0 with commit count source 99d02c3e61dc573d25d8a48c9286c800ac88971d
2025-02-12T09:23:31.3357030Z     INFO [02/12/25 9:23:30:54] Merge message 'Merge branch 'release/2.1.0'': 2.1.0 with commit count source a78151f46113e94d5cc58240bf48e7885a66491e
2025-02-12T09:23:31.3357422Z     INFO [02/12/25 9:23:30:54] Merge message 'Merge branch 'release/2.0.0'': 2.0.0 with commit count source a5a83fd66bdb8c04e4ccf1f4c50655feb49b49ad
2025-02-12T09:23:31.3357782Z     INFO [02/12/25 9:23:30:57] Git tag '2.4.0': 2.4.0 with commit count source f3f7eb475dbafaf31f9081d1b9c37a1673be7112
2025-02-12T09:23:31.3358112Z     INFO [02/12/25 9:23:30:57] Git tag '2.3.0': 2.3.0 with commit count source 70ff5ee645baa3ec74bc9c4e64f0b70fd7d10727
2025-02-12T09:23:31.3358439Z     INFO [02/12/25 9:23:30:57] Git tag '2.2.0': 2.2.0 with commit count source 99d02c3e61dc573d25d8a48c9286c800ac88971d
2025-02-12T09:23:31.3358772Z     INFO [02/12/25 9:23:30:57] Git tag '2.1.0': 2.1.0 with commit count source a78151f46113e94d5cc58240bf48e7885a66491e
2025-02-12T09:23:31.3359085Z     INFO [02/12/25 9:23:30:57] Git tag '2.0.0': 2.0.0 with commit count source a5a83fd66bdb8c04e4ccf1f4c50655feb49b49ad
2025-02-12T09:23:31.3359598Z     INFO [02/12/25 9:23:30:57] Git tag '1.18.0': 1.18.0 with commit count source 04ac1d542506ca7adbd559e2604c8e4aff32e7c0
2025-02-12T09:23:31.3359937Z     INFO [02/12/25 9:23:30:57] Git tag '1.17.0': 1.17.0 with commit count source c4c43f6c55c5cc29de9f046315e06ad40a018409
2025-02-12T09:23:31.3360272Z     INFO [02/12/25 9:23:30:57] Git tag '1.16.0': 1.16.0 with commit count source 59f27c9b30af25cb223839cb8f29715485787fa1
2025-02-12T09:23:31.3360603Z     INFO [02/12/25 9:23:30:57] Git tag '1.15.0': 1.15.0 with commit count source 2ff0a0ef8d8b6cedf13447fa095d53dbaefa167c
2025-02-12T09:23:31.3360929Z     INFO [02/12/25 9:23:30:57] Git tag '1.14.0': 1.14.0 with commit count source 4e67f3d59972376718451ffa91eb4cdc3ae63545
2025-02-12T09:23:31.3361258Z     INFO [02/12/25 9:23:30:57] Git tag '1.13.0': 1.13.0 with commit count source fd88af88c00c50ae64bccbf60bc23c61de68745b
2025-02-12T09:23:31.3361585Z     INFO [02/12/25 9:23:30:57] Git tag '1.12.0': 1.12.0 with commit count source 0761210758e3d96980d1cea703e78cb8e2dd7fc5
2025-02-12T09:23:31.3361918Z     INFO [02/12/25 9:23:30:57] Git tag '1.11.0': 1.11.0 with commit count source f777345f9db94342c61c362840cef239f842fe82
2025-02-12T09:23:31.3363757Z     INFO [02/12/25 9:23:30:57] Git tag '1.10.0': 1.10.0 with commit count source 5fba546655db69fe31eefbffd9be3e528bd0c28d
2025-02-12T09:23:31.3364148Z     INFO [02/12/25 9:23:30:57] Git tag '1.9.0': 1.9.0 with commit count source 776d9cf073263309bef239fad719de957c02ea6b
2025-02-12T09:23:31.3364478Z     INFO [02/12/25 9:23:30:57] Git tag '1.8.0': 1.8.0 with commit count source 06f1258123e57b46fbcff3dcc89000cc036ff514
2025-02-12T09:23:31.3364806Z     INFO [02/12/25 9:23:30:57] Git tag '1.7.0': 1.7.0 with commit count source ba355c074e7e0845ea196946207a91a68fce17ef
2025-02-12T09:23:31.3365130Z     INFO [02/12/25 9:23:30:57] Git tag '1.6.0': 1.6.0 with commit count source c28ed72f2ffee7621d69d1dbfbcbf45659a11917
2025-02-12T09:23:31.3365459Z     INFO [02/12/25 9:23:30:57] Git tag '1.5.0': 1.5.0 with commit count source a168ac827e954cd7371e8d9971ba10f874d19aa9
2025-02-12T09:23:31.3365791Z     INFO [02/12/25 9:23:30:57] Git tag '1.4.0': 1.4.0 with commit count source 88df235262d87540f1c53fd1f2ac7af7d2bc3f60
2025-02-12T09:23:31.3366120Z     INFO [02/12/25 9:23:30:57] Git tag '1.3.0': 1.3.0 with commit count source c49a1a91869dd7bda2fc1f57ba69d3665bc4fda7
2025-02-12T09:23:31.3367296Z     INFO [02/12/25 9:23:30:57] Git tag '1.2.0': 1.2.0 with commit count source 1bf31d8910bedf086582688f2a24aa67a7917c04
2025-02-12T09:23:31.3367628Z     INFO [02/12/25 9:23:30:57] Git tag '1.1.0': 1.1.0 with commit count source 8213191b4fd80d56c21c443ec12e495ad179de84
2025-02-12T09:23:31.3367954Z     INFO [02/12/25 9:23:30:57] Git tag '1.0.0': 1.0.0 with commit count source ec7565cb20384abc86d60a8e5025b64cdf19dc51
2025-02-12T09:23:31.3368314Z     INFO [02/12/25 9:23:30:78] Found multiple base versions which will produce the same SemVer (2.4.1), taking oldest source for commit counting (Git tag '2.4.0')
2025-02-12T09:23:31.3368694Z     INFO [02/12/25 9:23:30:78] Base version used: Git tag '2.4.0': 2.4.0 with commit count source f3f7eb475dbafaf31f9081d1b9c37a1673be7112
2025-02-12T09:23:31.3369012Z   INFO [02/12/25 9:23:30:78] End: Calculating base versions (Took: 364.08ms)
2025-02-12T09:23:31.3369336Z   INFO [02/12/25 9:23:30:78] 39 commits found between f3f7eb4 Merge branch 'release/2.4.0' and 02286cb Update azure-pipelines.yml for Azure Pipelines
2025-02-12T09:23:31.3369716Z   INFO [02/12/25 9:23:30:78] 39 commits found between f3f7eb4 Merge branch 'release/2.4.0' and 02286cb Update azure-pipelines.yml for Azure Pipelines
2025-02-12T09:23:31.3370019Z   INFO [02/12/25 9:23:30:79] Begin: Creating dictionary
2025-02-12T09:23:31.3370267Z   INFO [02/12/25 9:23:30:80] End: Creating dictionary (Took: 5.20ms)
2025-02-12T09:23:31.3370592Z   INFO [02/12/25 9:23:30:80] Begin: Storing version variables to cache file D:\a\1\s\.git\gitversion_cache\9AF505F732B9C1A9A32527F6D2EFB5868BDFD6AB.yml
2025-02-12T09:23:31.3370985Z   INFO [02/12/25 9:23:30:85] End: Storing version variables to cache file D:\a\1\s\.git\gitversion_cache\9AF505F732B9C1A9A32527F6D2EFB5868BDFD6AB.yml (Took: 54.69ms)
2025-02-12T09:23:31.3371900Z Executing GenerateSetVersionMessage for 'AzurePipelines'.
2025-02-12T09:23:31.3903027Z Executing GenerateBuildLogOutput for 'AzurePipelines'.
2025-02-12T09:23:31.3936107Z {
2025-02-12T09:23:31.3936264Z   "Major": 2,
2025-02-12T09:23:31.3936409Z   "Minor": 4,
2025-02-12T09:23:31.3936543Z   "Patch": 1,
2025-02-12T09:23:31.3936696Z   "PreReleaseTag": "",
2025-02-12T09:23:31.3936862Z   "PreReleaseTagWithDash": "",
2025-02-12T09:23:31.3937029Z   "PreReleaseLabel": "",
2025-02-12T09:23:31.3937194Z   "PreReleaseLabelWithDash": "",
2025-02-12T09:23:31.3937359Z   "PreReleaseNumber": null,
2025-02-12T09:23:31.3937535Z   "WeightedPreReleaseNumber": 60000,
2025-02-12T09:23:31.3937716Z   "BuildMetaData": 39,
2025-02-12T09:23:31.3937883Z   "BuildMetaDataPadded": "0039",
2025-02-12T09:23:31.3938111Z   "FullBuildMetaData": "39.Branch.master.Sha.02286cbdd7c6a5cb4e5f92dadd10222d4716d9d1",
2025-02-12T09:23:31.3938507Z   "MajorMinorPatch": "2.4.1",
2025-02-12T09:23:31.3938654Z   "SemVer": "2.4.1",
2025-02-12T09:23:31.3938806Z   "LegacySemVer": "2.4.1",
2025-02-12T09:23:31.3938968Z   "LegacySemVerPadded": "2.4.1",
2025-02-12T09:23:31.3939138Z   "AssemblySemVer": "2.4.1.0",
2025-02-12T09:23:31.3939307Z   "AssemblySemFileVer": "2.4.1.0",
2025-02-12T09:23:31.3939466Z   "FullSemVer": "2.4.1+39",
2025-02-12T09:23:31.3939687Z   "InformationalVersion": "2.4.1+39.Branch.master.Sha.02286cbdd7c6a5cb4e5f92dadd10222d4716d9d1",
2025-02-12T09:23:31.3939910Z   "BranchName": "master",
2025-02-12T09:23:31.3940072Z   "EscapedBranchName": "master",
2025-02-12T09:23:31.3940259Z   "Sha": "02286cbdd7c6a5cb4e5f92dadd10222d4716d9d1",
2025-02-12T09:23:31.3940439Z   "ShortSha": "02286cb",
2025-02-12T09:23:31.3940589Z   "NuGetVersionV2": "2.4.1",
2025-02-12T09:23:31.3940747Z   "NuGetVersion": "2.4.1",
2025-02-12T09:23:31.3940906Z   "NuGetPreReleaseTagV2": "",
2025-02-12T09:23:31.3941069Z   "NuGetPreReleaseTag": "",
2025-02-12T09:23:31.3941263Z   "VersionSourceSha": "f3f7eb475dbafaf31f9081d1b9c37a1673be7112",
2025-02-12T09:23:31.3941458Z   "CommitsSinceVersionSource": 39,
2025-02-12T09:23:31.3941642Z   "CommitsSinceVersionSourcePadded": "0039",
2025-02-12T09:23:31.3942076Z   "UncommittedChanges": 0,
2025-02-12T09:23:31.3942239Z   "CommitDate": "2025-02-12"
2025-02-12T09:23:31.3942377Z }
2025-02-12T09:23:31.3942538Z   INFO [02/12/25 9:23:31:31] Done writing 
2025-02-12T09:23:31.4054354Z ##[section]Async Command Start: Update Build Number
2025-02-12T09:23:31.6868646Z Update build number to 2.4.1+39 for build 128854
2025-02-12T09:23:31.6868859Z ##[section]Async Command End: Update Build Number
2025-02-12T09:23:31.6870479Z ##[section]Finishing: Run > gitversion execute (Windows)

Logs from @3:

Starting: GitVersion > setup
==============================================================================
Task         : Setup GitVersion Task
Description  : Easy Semantic Versioning (https://semver.org/) for projects using Git
Version      : 3.1.11
Author       : GitTools Contributors
Help         : See the [documentation](https://gitversion.net/docs/) for help
==============================================================================
Running on: 'Azure Pipelines'
Disable Telemetry
--------------------------
Acquiring GitVersion.Tool for version spec: 5.12.0
--------------------------
Looking for local tool [email protected]
Found tool [email protected] at C:\hostedtoolcache\windows\GitVersion.Tool\5.12.0
--------------------------
GitVersion.Tool version: 5.12.0 found in local cache at C:\hostedtoolcache\windows\GitVersion.Tool\5.12.0.
--------------------------
Prepending C:\hostedtoolcache\windows\GitVersion.Tool\5.12.0 to PATH
Updated PATH: C:\hostedtoolcache\windows\GitVersion.Tool\5.12.0;C:\hostedtoolcache\windows\GitVersion.Tool\5.12.0\x64;C:\agents\4.251.0\externals\git\cmd;C:\agents\4.251.0\externals\git\mingw64\bin;C:\Program Files\MongoDB\Server\5.0\bin;C:\aliyun-cli;C:\vcpkg;C:\Program Files (x86)\NSIS\;C:\tools\zstd;C:\Program Files\Mercurial\;C:\hostedtoolcache\windows\stack\3.3.1\x64;C:\cabal\bin;C:\\ghcup\bin;C:\mingw64\bin;C:\Program Files\dotnet;C:\Program Files\MySQL\MySQL Server 8.0\bin;C:\Program Files\R\R-4.4.2\bin\x64;C:\SeleniumWebDrivers\GeckoDriver;C:\SeleniumWebDrivers\EdgeDriver\;C:\SeleniumWebDrivers\ChromeDriver;C:\Program Files (x86)\sbt\bin;C:\Program Files (x86)\GitHub CLI;C:\Program Files\Git\bin;C:\Program Files (x86)\pipx_bin;C:\npm\prefix;C:\hostedtoolcache\windows\go\1.21.13\x64\bin;C:\hostedtoolcache\windows\Python\3.9.13\x64\Scripts;C:\hostedtoolcache\windows\Python\3.9.13\x64;C:\hostedtoolcache\windows\Ruby\3.0.7\x64\bin;C:\Program Files\OpenSSL\bin;C:\tools\kotlinc\bin;C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.442-6\x64\bin;C:\Program Files\ImageMagick-7.1.1-Q16-HDRI;C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin;C:\ProgramData\kind;C:\ProgramData\Chocolatey\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\PowerShell\7\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files (x86)\WiX Toolset v3.14\bin;C:\Program Files\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Microsoft SQL Server\160\DTS\Binn\;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\ProgramData\chocolatey\lib\pulumi\tools\Pulumi\bin;C:\Program Files\CMake\bin;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.9.9\bin;C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code;C:\Program Files\Microsoft SDKs\Service Fabric\Tools\ServiceFabricLocalClusterManager;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\GitHub CLI\;c:\tools\php;C:\Program Files (x86)\sbt\bin;C:\Program Files\Amazon\AWSCLIV2\;C:\Program Files\Amazon\SessionManagerPlugin\bin\;C:\Program Files\Amazon\AWSSAMCLI\bin\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\LLVM\bin;C:\Users\VssAdministrator\.dotnet\tools;C:\Users\VssAdministrator\.cargo\bin;C:\Users\VssAdministrator\AppData\Local\Microsoft\WindowsApps
Set GITVERSION_PATH to C:\hostedtoolcache\windows\GitVersion.Tool\5.12.0
dotnet-gitversion installed successfully
dotnet-gitversion Output:
-------------------
undefined
-------------------
GitVersion setup successfully
Finishing: GitVersion > setup
Starting: Run > gitversion execute (Windows)
==============================================================================
Task         : Execute GitVersion Task
Description  : Easy Semantic Versioning (https://semver.org/) for projects using Git
Version      : 3.1.11
Author       : GitTools Contributors
Help         : See the [documentation](https://gitversion.net/docs/) for help
==============================================================================
Running on: 'Azure Pipelines'
Disable Telemetry
Command: git -C D:/a/1/s rev-parse --is-shallow-repository
Command: C:\hostedtoolcache\windows\GitVersion.Tool\5.12.0\dotnet-gitversion.exe --roll-forward Major D:/a/1/s /output json /l console
##[error]GitVersion output is not valid JSON
dotnet-gitversion Output:
-------------------
undefined
-------------------
undefined
Finishing: Run > gitversion execute (Windows)

@DSpirit
Copy link
Contributor

DSpirit commented Mar 3, 2025

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_PATH resulted in:

x64
x64.complete

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:

  - task: gitversion/setup@3
    displayName: gitversion/setup
    inputs:
      versionSpec: '6.0.*'
  
  - pwsh: |
      $gitVersion = Get-ChildItem "${env:GITVERSION_PATH}" -Filter "dotnet-gitversion"
      if (!$gitVersion) {
        $gitVersion = Get-ChildItem "${env:GITVERSION_PATH}" -Recurse -Filter "dotnet-gitversion"
        Write-Host "Setting 'GITVERSION_PATH' to '$($gitVersion.DirectoryName)'"
        Write-Output "##vso[task.setvariable variable=GITVERSION_PATH]$($gitVersion.DirectoryName)"
      }
    displayName: gitversion/configure
  
  - task: gitversion/execute@3
    displayName: gitversion/execute

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'

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

9 participants