Reputation: 5977
lets say we have the yaml below.
jobs:
- template: templates/jobs.yml
parameters:
myBranch: ${{ variables.Build.SourceBranch }}
I notice we cannot compile the pre-defined variables as template expression variables but I didn't find any documentation about this in the this doc
So, Is it possible to use pre-defined variables like Build.SourceBranch
as template expression variables ${{ var }}
in Azure Pipeline?
Upvotes: 0
Views: 663
Reputation: 40779
This is available but not for all variables.
You should check if variable is available in the template.
And Build.SourceBranch is available
I tested this
trigger: none
jobs:
- template: build.yml
parameters:
name: ${{ variables['Build.SourceBranch'] }}
and
parameters:
- name: name # defaults for any parameters that aren't specified
default: ''
jobs:
- job: Test
steps:
- script: echo '${{ parameters.name }}'
and I got
Generating script.
Script contents:
echo 'refs/heads/main'
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/a699d41a-2dd0-4109-89bb-33829fdf5180.sh
refs/heads/main
Finishing: CmdLine
Upvotes: 1