Azure pipeline powershell script returns incorrect result

pantonis

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

Cpt.Whale

If $(version) -eq $ver is false, then maybe they are different types somehow? Try manually converting to strings:

if ("$(version)" -eq "$ver") {

in regards to your comment - I'm not really familiar with az pipeline, but maybe you can convert your remote variables like so?

[string]($(version))

types are also objects, so to see the current type as a string, use $var.GetType().name instead

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Passing JSON variable into PowerShell script in Azure Pipeline

Pass a script argument in Azure DevOps pipeline which runs a Powershell script

Running azure powershell script through YAML release pipeline

how Access Variable in Azure script btw Powershell in Dev Ops Pipeline

How to use powershell/bash script file in azure pipeline template

azure pipeline variable created in powershell script not displaying value

Is it possible to cancel a Azure DevOps pipeline via PowerShell script?

MySQL MAX returns incorrect result

Azure DevOps: How to retrieve a build artifact from build Azure Pipeline from a PowerShell Script in Release Pipeline?

ADF - Pipeline with powershell script

Powershell script in jenkins pipeline

Azure devops rest api result looping using powershell script

PHP script returns no result

Powershell assert pipeline returns not an array

Is there something I am fundamentally missing from this powershell script I am running in Azure Powershell (release pipeline)?

Azure DevOps pipeline, Azure PowerShell 4.* script loses AzContext in "ForEach -Parallel"?

Azure Pipeline returns "undefined" in filepath

File.isFile() returns incorrect result?

Gremlin using select in hasId returns incorrect result

lambdified sympy expression returns incorrect result

getting an array from webservice returns an incorrect result

removing rows without returns incorrect result

Kadane algorithm implementation returns incorrect result

PL/pgSQL function returns incorrect bitwise result

TimeZoneInfo.ConvertTimeFromUtc returns incorrect result

MarkLogic Query By Example returns incorrect result

Array formula with SUM Function returns incorrect result

Google Maps Autocomplete Place returns incorrect result

in MySQL, MAX() command returns an incorrect result