I want to pass a variable called publish
defined in the pipeline definition UI into a template called echo.yml
from the main pipeline.yml
then in the template use the value of the variable as a condition on a task running or not.
So far no success.
Is this actually possible ?
Simplified example below, the real use case is to control whether or not a publish task executes.
echo.yml
:
parameters:
- name: 'desc'
type: string
default: none
- name: 'publish'
type: string
default: 'false'
steps:
- task: Bash@3
condition: ${{ parameters.publish }}
inputs:
targetType: 'inline'
script: |
echo desc is ${{ parameters.desc }}
echo publish is ${{ parameters.publish }}
pipeline.yml
:
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: |
# Write your commands here
echo SBN IS $(Build.SourceBranchName)
echo SB IS $(Build.SourceBranch)
- template: echo.yml
parameters:
desc: 'my description'
publish: ${{ variables.publish }}
2
Answers
Given that you want to run a task or not based on a parameter, you can use a template expression
${{ if ... }}
instead of using a condition.Example:
Using a condition:
Note:
publish
can be changed toboolean
, which will be displayed as a checkbox when queuing a new build.If you define the variable in
pipeline definition UI
, it cannot get the value as parameter${{ variables.publish }}
for template.Instead, you can define the variable in main yaml directly,it works then.