I am trying to pass a variable, set by a ps1 script, as a parameter to a template yaml file in an azure pipeline yaml. However no matter what I try the variable is never expanded when it reaches the template.
parameters:
- name: myparam
type: boolean
default: 'true'
stages:
- stage: stage1
variables:
override: 'true'
jobs:
- job: FilterJob
- task: PowerShell@2
name: ps1task
inputs:
targetType: inline
script: |
$override = "some value"
Write-Host "##vso[task.setvariable variable=override;isOutput=true]$override"
- ${{ if eq(parameters.myparam, true) }}:
- template: Mytemplate.yml
parameters:
varPassedToTemplate: $(variables.override) ### VARIABLE DOES NOT EXPAND
The variable 'varPassedToTemplate' always ends up as a litteral of whatever is after the ':'
I believe ${{ if eq(parameters.myparam, true) }}:
is compile time and isn't expanded during runtime but does that also apply to params passed to a template? Is there a way to expand the variable 'varPassedToTemplate' or is my syntax just wrong? (BTW I have tried multiple syntaxes)
This has been driving me crazy for days so any help much appreciated.
Based on your YAML sample, you are defining the Stages or Jobs in the Template.
The variables you define in stage1 cannot be passed directly to the next stage or job.
To solve this issue, I suggest that you can define the jobs in the template and use Stage output variable to accept the variable in stage1.
Refer to my sample:
Template:
main YAML:
Result: