0
votes

I have a build pipeline and the first task is a PowerShell script which sets some variables. I have the git command to get the latest tag from a branch in the repo.

git tag -l v* | tail -n1

I am trying to use this to add to the build name. The command above has the output of: v1.4.0

However when I run:

$AppVersion= (git tag -l v* | tail -n1)
Write-host $AppVersion

I am getting the following error:

tail : The term 'tail' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

2
A PowerShell tail -n 1 equivalent is Select-Object -Last 1.AdminOfThings

2 Answers

1
votes

I have manage to figure a workaround from the Tail error I was seeing.

$TagArray= git tag -l v*
$AppVersion = $TagArray[$TagArray.Count – 1]

I add the results returned from: git tag -l v* into an array and then I select the last element from that array.

0
votes

You can use Git Describe to get the latest tag

$AppVersion= (git describe --match "v*" <BranchName>)