1

I want to get the last tag and assign it to a variable created in my Azure Pipeline this is what I'm doing Create variable enter image description here

Added a powershell task enter image description here

And I get this error enter image description here

Any ideas? Thanks

Khaled
  • 317
  • 2
  • 7

2 Answers2

1

Get git last tag into Azure pipeline variable

The code I tested was also incorrect. To get the git last tag, you could use following powershell scripts, it works fine on my side:

cd $(System.DefaultWorkingDirectory)
$Latesttag = $(git describe --tags $(git rev-list --tags --max-count=1))

Write-Host "The latest git tag is $Latesttag "

enter image description here

You could check this thread for some details.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • That worked thanks, But what's wrong with $(git for-each-ref refs/tags --sort=-taggerdate --format="%(refname:short)" --count=1) ? It seems to return also the correct value. – Khaled May 15 '20 at 08:27
1

It was not clear but part of the question was how to set an Azure pipeline variable in powerShell task

$tag = $(git describe --tags $(git rev-list --tags --max-count=1))
Write-Host "##vso[task.setvariable variable=version]$tag"

version is the variable to set

Khaled
  • 317
  • 2
  • 7