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]
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
trigger:
- none
pool:
vmImage: ubuntu-latest
variables:
VersionId: 12345
extends:
template: Directory/To/The/Template.yml
parameters:
projectVersionId: ${{variables.VersionId }}
Directory/To/The/Template.yml
parameters:
- name: projectVersionId
type: number
default: 1
steps:
- task: PowerShell@2
condition: ${{ eq(parameters.projectVersionId, 12345)}}
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
You can see that we pass the check step successfully:
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
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