Getting 'fatal: No tags can describe' when running 'git describe' in an azure pipeline


I have a Powershell task that sets the app version using the current git tag. When the pipeline runs the Powershell task throws this error message:

fatal: No tags can describe 'b9cee9799b91f108547e1fcf0c8fcb1abef.....'.
Try --always, or create some tags.
##[error]PowerShell exited with code '1'.

When I run the same command git describe --abbrev=0 in a Powershell window on the same branch it works fine. I’ve tried removing --abbrev=0 and I get the same error. I also tried adding an extra -- but got an error of fatal: Not a valid object name --abbrev=0.

Here is the Powershell task YAML:

  - task: [email protected]
    displayName: 'Set Server Version'
      targetType: inline
      script: |
        $releasever = git describe --abbrev=0
        $AppSettings = Get-Content $(Build.BinariesDirectory)/publish/api/appsettings.json -raw | ConvertFrom-Json
        $AppSettings.Version.Version = $releasever;
        $AppSettings.Version.Branch = "$(Build.SourceBranchName)";
        $AppSettings | ConvertTo-Json -Depth 100 | Set-Content $(Build.BinariesDirectory)/publish/api/appsettings.json    
      errorActionPreference: stop
      warningPreference: continue
      pwsh: true


I figured out the solution. You have to set the fetchDepth in the Azure Pipeline YAML to 0.

For example:

- checkout: self
  clean: false
  fetchDepth: 0

Hope this helps those who’ve encountered the same issue.

Answered By – mdailey77

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published