Make an azure build pipeline yaml file with a boolean parameter DoFlag defaulting to…
- User
Make an azure build pipeline yaml file with a boolean parameter DoFlag defaulting to
false. The pipeline should have a powershell task, which depending on the value of DoFlag should create a task variable NugetSuffix set to a string value "hello" if false or "world" if true. - Assistant
To create an Azure Pipeline with a boolean parameter
DoFlagthat defaults tofalseand a PowerShell task that sets a variableNugetSuffixto either "hello" or "world" based on theDoFlagvalue, follow the YAML definition below. This YAML file defines the parameter at the top and then uses a PowerShell script within a task to conditionally set the value. It then uses this value in subsequent steps or tasks within the pipeline as required. - User
shouldn't the parameters.DoFlag be surrounded with something like {} or symbol?
- Assistant
You are correct in observing a detail concerning the syntax used to reference parameters within the YAML pipeline, particularly in expressions and specific contexts. The correct way to reference a pipeline parameter within expressions is by using the
${{ parameters.parameterName }}syntax. This syntax ensures that Azure DevOps correctly interprets and substitutes the parameter's value at the time of pipeline execution.Given this, the initial PowerShell script provided in the example should indeed utilize this syntax to correctly reference the
DoFlagparameter within a conditional expression. Here's the corrected part of the YAML with the appropriate syntax for referencing theDoFlagparameter within the PowerShell task:yaml