【发布时间】: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