$Env:APPVEYOR_REPO_TAG powershell variable evaluates to true on non-tags
Asked Answered
R

1

5

I have an appveyor.yml definition which contains the fragment

init:
- ps: $Env:LABEL = If ($Env:APPVEYOR_REPO_TAG) { "Tag" + $Env:APPVEYOR_REPO_TAG_NAME } else { "nontaglabel" }

When later trying to access %LABEL%, on non-tag commits it contains the plain string "Tag". I expected it to contain the string "nontaglabel".

On tag commits, it contains the expected string Tag with the tag name as a suffix.

How can I assign the environment variable "nontaglabel" to the environment variable on commits that aren't tags?

Roee answered 29/11, 2016 at 16:24 Comment(0)
P
7

This is because $Env:APPVEYOR_REPO_TAG has string value of "false" on non-tag commits. Thus ($Env:APPVEYOR_REPO_TAG) is evaluated to true as string value is not null or empty. Please use ($Env:APPVEYOR_REPO_TAG -eq $true) or ($Env:APPVEYOR_REPO_TAG -eq "true") -- both will work.

Prognathous answered 29/11, 2016 at 18:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.