Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

steps:
  - task: PowerShell@2
    displayName: 'Set Server Version'
    inputs:
      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
like image 455
mdailey77 Avatar asked Oct 14 '25 20:10

mdailey77


1 Answers

September 2022 Azure Devops made an update to the default behaviour of checkouts. They went from not doing shallow fetches to a fetch depth of 1, and from syncing tags to not syncing tags. This applies to all pipelines created after the september 2022 update; previously created pipelines keep the old behaviour (for me, this lead to a lot of confusion!).

I solved the issue by adding

  - checkout: self
    fetchTags: true
    fetchDepth: 0

as the first build step.

Ref.:

  • https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-checkout?view=azure-pipelines#remarks
  • https://learn.microsoft.com/en-us/azure/devops/release-notes/2022/sprint-209-update?tabs=yaml#do-not-sync-tags-when-fetching-a-git-repository
like image 105
Ida Avatar answered Oct 17 '25 13:10

Ida