Share via

GitVersion task is not working in the Azure devops self-hosted agent

Govardhan Reddy 10 Reputation points
2025-04-22T07:09:32.02+00:00

Hi,

I am using the GitVersion tool to generate the build number in the azure devops build pipelines. The GitVersion task is able to generate the build number in the Microsoft-hosted agent, but not able to generate the build number in the self-hosted agent. The error it is showing [error]GitVersion output is not valid JSON. And the task which I am using is

      - task: gitversion/setup@3
        inputs:
          versionSpec: '5.x'

      - task: gitversion/execute@3
        inputs:
          useConfigFile: true
          configFilePath: './git-version.yaml'

I have tried several things found online, but not working. Any workaround?

Best Regards,

Govardhan.

Azure DevOps

2 answers

Sort by: Most helpful
  1. Muhammad Zubair 0 Reputation points
    2025-07-28T11:43:59.39+00:00

    If we are facing this error "Disable Telemetry ##[error]Unable to locate executable file: dotnet" under this below Microsoft Extension , It is unable to handle the .net 9 version calculation. This issue is not handled after the gitversion.setup@2.0.0 updated .https://marketplace.visualstudio.com/items?itemName=gittools.gitversion

    • gitversion.setup@3.0.0

    Solution:
    To resolve this error we need to use dot task on additionally, that will handle the dot net version on the agent pool (machine)

      - task: UseDotNet@2
        inputs:
          version: 9.x #change the version according to  your application
    
      - task: gitversion/setup@3.0.0
        displayName: Setup GitVersion
        inputs:
          versionSpec: '5.x'
          includePrerelease: false
          preferLatestVersion: true
    
    

    Was this answer helpful?

    0 comments No comments

  2. Gaurav Kumar 790 Reputation points Moderator
    2025-04-28T06:44:03.2633333+00:00

    Hi Govardhan Reddy,

    Instead of using the GitHub Actions version (gitversion/setup@3 and gitversion/execute@3),

    Use the official GitVersion Azure DevOps extension tasks:

    These are designed for Azure Pipelines and do not have the same issues.

    • gittools.gitversion.setup@0
    • gittools.gitversion.execute@0

    Here’s the corrected YAML:

    trigger:
    - main
    pool:
      name: Self-Hosted-Agent-Pool
    steps:
    - task: gittools.gitversion.setup@0
      inputs:
        versionSpec: '5.x'
    - task: gittools.gitversion.execute@0
      inputs:
        useConfigFile: true
        configFilePath: './git-version.yaml'
    - script: echo "##vso[build.updatebuildnumber]$(GitVersion.FullSemVer)"
      displayName: 'Set Build Number'
    

    The gittools.gitversion.setup@0 and gittools.gitversion.execute@0 tasks are maintained specifically for Azure DevOps Pipelines, independent of GitHub Actions releases.

    Reference: Official GitVersion Azure DevOps Extension on Visual Studio Marketplace

    This method fully resolves the issue, and you’ll be able to run GitVersion successfully on your pipelines.

    Hope it helps!


    Please do not forget to click "Accept the answer” and Yes wherever the information provided helps you, this can be beneficial to other community members.

    If you have any other questions or still running into more issues, let me know in the "comments" and I would be happy to help you.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.