I have an Azure DevOps Build Pipeline YAML file that takes variables from the ‘Variables’ button as opposed to having "variables:" in the YAML file itself.
I’m trying to pass a Number to a step that requires a Number as the parameter, however the pipeline is failing to run because it’s saying the value is not a valid Number.
Inside the "Variables" button, I have the variable VersionId
with the given value 12345
.
extends:
template: Directory/To/The/Template.yaml@Name
parameters:
projectVersionId: $(VersionId)
Is there a way I can explicitly state that this a number, and not a string?
I have tried using both ${{variables.VersionId}}
and $[variables.VersionId]
2
Answers
Try
$[ variables['VersionId'] ]
This somewhat explains the reason why this works
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#understand-variable-syntax
The issue was that run-time variables are not yet available at the time the value pass the template parameter.
And you need to specify the value type via parameter definition:
give_parameter.yml
Directory/To/The/Template.yml
You can see that we pass the check step successfully: