I'm just starting to work with runtime parameters in Azure Pipelines and there's something I can't quite figure out. Considering this Azure Pipelines YAML:
parameters:
- name: deployEnvironment
displayName: Select your target environment.
type: string
default: Build_only
values:
- Build_only
- TST
- PP
- P
- name: releaseName
type: string
default: ''
steps:
- task: ....
Why is releaseName a required parameter? I was hoping that by specifying default: ''
it would be optional to be left empty. The documentation doesn't mention if parameters can be made optional.
Following up on Kryzstof's answer, I experimented a little further and it seems that a string consisting only of whitespaces is interpreted as empty:
It seems that this single whitespace is interpreted as empty (I've also tried multiple whitespaces).
parameters:
- name: myString
type: string
default: ' '
steps:
- task: PowerShell@2
inputs:
targetType: inline
script: |
$MS = $ENV:MS
Write-Host "myString value is '$MS'"
Write-Host "Its length is $($MS.Length)"
Write-Host "is it null or empty? $([System.String]::IsNullOrEmpty($MS))"
Write-Host "Is it null or whitespace? $([System.String]::IsNullOrWhiteSpace($MS))"
env:
MS: ${{ parameters.myString }}
This yields:
myString value is '' Its length is 0 is it null or empty? True Is it null or whitespace? True