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

Govardhan Reddy 5 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
{count} vote

1 answer

Sort by: Most helpful
  1. Gaurav Kumar 295 Reputation points Microsoft External Staff 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.


Your answer

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