Search code examples
yamlazure-pipelinesdevopsgitversion

GitVersion on Azure DevOps yaml pipeline fails on Linux


I am using GitVersion in Azure DevOps yaml pipeline. It works great on windows-2022 agent but with ubuntu-latest or ubuntu-20.04 the GitVersion step always fails with:

/opt/hostedtoolcache/dotnet/dotnet tool install GitVersion.Tool --tool-path /home/vsts/work/_temp --version 5.10.3
You can invoke the tool using the following command: dotnet-gitversion
Tool 'gitversion.tool' (version '5.10.3') was successfully installed.
Caching tool: GitVersion.Tool 5.10.3 x64
##[error]Error: EINVAL: invalid argument, readlink '/opt/hostedtoolcache/dotnet/dotnet'
Finishing: GitVersion

The pipeline is pretty straight forward:

pool:
  # vmImage: windows-2022
  vmImage: ubuntu-20.04

trigger:
- main

variables:
- name: buildConfiguration
  value: Release
- name: solutionFile
  value: src/mySolution.sln
- name: packagesToPush
  value: stages:
- stage: Build
  displayName: Build, Pack and Push NuGet Package

  jobs:
  - job: BuildSolution
    displayName: Build Solution
    variables:
      GitVersion.SemVer: ""

    steps:
    - task: UseDotNet@2
      displayName: Use .NET 6
      inputs:
        version: 6.0.x

    - task: UseGitVersion@5
      displayName: GitVersion
      inputs:
        versionSpec: 5.x
        updateAssemblyInfo: false

Does anyone have an idea what might be the problem?


Solution

  • Tested the same task and got the same issue.

    ##[error]Error: EINVAL: invalid argument, readlink '/opt/hostedtoolcache/dotnet/dotnet'

    The path: /opt/hostedtoolcache/dotnet/dotnet is the value of the environment variable Dotnet_Root.

    The expected value is /opt/hostedtoolcache/dotnet. This value is set in the task: UseDotNet@2.

    The variable set in UseDotNet@2 task is correct, but the task:UseGitVersion@5 is using the wrong value of the Dotnet_Root(value:/opt/hostedtoolcache/dotnet/dotnet ).

    The issue indeed from the task itself.

    To solve this issue, you can set the path in UseDotNet@2( installationPath: ../share/dotnet ).

    Here is the YAML example:

    pool:
      # vmImage: windows-2022
      vmImage:  ubuntu-latest
    
    trigger:
    - main
    
    variables:
    - name: buildConfiguration
      value: Release
    - name: solutionFile
      value: src/mySolution.sln
    - name: packagesToPush
      value: 
    stages:
    - stage: Build
      displayName: Build, Pack and Push NuGet Package
    
      jobs:
      - job: BuildSolution
        displayName: Build Solution
        variables:
          GitVersion.SemVer: ""
    
        steps:
        - task: UseDotNet@2
          displayName: Use .NET 6
          inputs:
            version: 6.0.x
            installationPath: ../share/dotnet
      
        - task: UseGitVersion@5
          displayName: GitVersion
          inputs:
            versionSpec: 5.x
            updateAssemblyInfo: false
    

    Then it will work.

    On the other hand, the task: UseGitVersion is deprecated. This means that the task will not update any more. Refer to this link: GitVersion.

    We suggest that you can change to use the extension: GitTools As you said in comment, it can work fine.