skip to Main Content

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


  1. 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:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search