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
This is really strange. But if you put instead of ''
a space ' '
you will be able to trigger pipeline, even deleting that space from field.
As per the documentation, "parameters cannot be optional".
Putting a space ' '
as the default value will work (as Krzysztof suggested), but the space will remain in the field. If you delete the space in the field so that there is no text value, the default value of ' '
will be used when the pipeline is run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With