In Azure Pipelines, I need to have an optional variable (say BuildConfiguration
) set either in Pipeline settings UI or at queue time
- If the variable exists in Pipeline settings UI or at queue-time, then the corresponding value,
- If the variable does not exist, then
Release
should be the default value,
that should be passed for --configuration
in DotNetCoreCLI task for command: build
I tried using --configuration $(BuildConfiguration)
, but it fails if the variable BuildConfiguration
is not defined/set
We can use coalesce
to achieve this,
first, we’ll get the value to an internal variable, _BuildConfiguration
using coalesce
with Release
as the fallback value,
variables:
- name: _BuildConfiguration
value: "$[ coalesce(variables['BuildConfiguration'], 'Release') ]"
then we use the newly defined internal variable to set --configuration
,
- task: DotNetCoreCLI@2
inputs:
command: build
arguments: "--configuration $(_BuildConfiguration)"