I have the following tasks in an azure pipeline:
- task: PowerShell@2
displayName: Identiying the version fro the .csproj file
inputs:
targetType: "inline"
script: |
$xml = [Xml] (Get-Content ./src/MyProject/MyProject.csproj)
$version = $xml.Project.PropertyGroup.Version
echo $version
echo "##vso[task.setvariable variable=version]$version"
- task: PowerShell@2
displayName: Checking if the git tag with current version already
inputs:
targetType: "inline"
script: |
$ver=git tag -l $(version)
Write-Host "Project file version is $(version)"
Write-Host "Received from git tag $ver"
if ($(version) -eq $ver) {
Write-Error "Tag $(version) already exists"
}
else {
Write-Host "Tag does not exist"
}
It basically pulls the version from the csproj file, create a pipeline parameter and then calls git tag -l to check if that version already exists as tag.
The problem here is that the versions we extract from the .csproj file and the git are the same, yet the if command is not evaluated but rather else is executed.
This is the output log of the azure pipeline:
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\e1cb6bb9-fbd4-4282-a4cc-e74f89ac7660.ps1'"
Project file version is 0.2.5
Received from git tag 0.2.5
Tag does not exist
Why does this happen since they are equal? The result should be Tag 0.2.5 already exists
$(version) -eq $veris false, then maybe they are different types somehow? Try manually converting to strings:if ("$(version)" -eq "$ver") {$(version).GetType()and even tried to convert it to string using[string]$(version)but it never worked. Your trick did the job. Thanks again. Write this as an answer so that I can mark it