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
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.:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With