We are trying to run a task conditionally, but the condition always seems to be true, even if it shouldn't. We have 3 files that are passing a parameter from the devops variables down to each file:
api1.yml
stages:
- template: api2.yml
parameters:
myParam: $(MyParam)
api2.yml
parameters:
- name: myParam
type: string
default: ''
stages:
jobs:
- deployment: Web
environment:
resourceType: VirtualMachine
displayName: 'IIS Deployment'
strategy:
runOnce:
deploy:
steps:
- download: none
- download: release
artifact: Api
displayName: 'Download Api Artifact'
- template: api3.yml
parameters:
myParam: ${{ parameters.myParam}}
api3.yml
parameters:
- name: myParam
type: string
default: ''
steps:
- ${{ if ne('${{ parameters.myParam}}', '') }}:
- task: PowerShell@2
displayName: Do something .${{ parameters.myParam}}.
continueOnError: true
inputs:
targetType: 'inline'
script: |
echo 'Test'
The value for "$(MyParam)" comes from the devops library variables, and has no value set (Just empty). Also the output from the display name of api3.yml shows "Do something .." which indicates, that the value is an empty string. I have also tried to change the if condition:
${{ if ne(parameters.myParam, '') }}:
${{ if parameters.myParam }}:
${{ if and(ne(parameters.myParam, ''), parameters.myParam) }}:
${{ if gt(length(parameters.myParam), 1) }}:
But none of it works. Especially the gt (greater than) check is confusing, because somehow there must be a string with at least 1 character. I guess somehow the syntax is wrong for the if statement.
How can we make this if check work?