【问题标题】:Getting 'fatal: No tags can describe' when running 'git describe' in an azure pipeline在天蓝色管道中运行 \'git describe\' 时获取 \'fatal: No tags can describe\'
【发布时间】:2022-11-14 22:55:12
【问题描述】:

我有一个 Powershell 任务,它使用当前的 git 标签设置应用程序版本。当管道运行 Powershell 任务时会抛出此错误消息:

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

当我在同一分支的 Powershell 窗口中运行相同的命令 git describe --abbrev=0 时,它工作正常。我尝试删除 --abbrev=0 并得到同样的错误。我还尝试添加一个额外的--,但出现fatal: Not a valid object name --abbrev=0 的错误。

这是 Powershell 任务 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

【问题讨论】:

    标签: git powershell azure-pipelines


    【解决方案1】:

    我想出了解决方案。您必须将 Azure Pipeline YAML 中的 fetchDepth 设置为 0。

    例如:

    - checkout: self
      clean: false
      fetchDepth: 0
    

    希望这对遇到同样问题的人有所帮助。

    【讨论】:

      【解决方案2】:

      2022 年 9 月 Azure Devops 对检出的默认行为进行了更新。他们从不做浅提取到提取深度为 1,从同步标签到不同步标签。这适用于所有管道创建2022年9月更新后;以前创建的管道保持旧的行为(对我来说,这会导致很多混乱!)。

      我通过添加解决了这个问题

        - checkout: self
          fetchTags: true
          fetchDepth: 0
      

      作为第一个构建步骤。

      参考:

      【讨论】:

        猜你喜欢
        • 2014-07-19
        • 2018-03-13
        • 2020-05-19
        • 2021-11-10
        • 1970-01-01
        • 2021-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多