I have a yaml pipeline the runs the following templates/variables:
variables:
- template: vars/global.yaml
steps:
- template: steps/debug-vars.yaml
This is the global.yaml:
variables:
isMain: ${{ eq(variables['Build.SourceBranch'], 'refs/heads/main') }}
isProduction: ${{ eq(variables['Build.SourceBranch'], 'refs/heads/production') }}
isTag: ${{ startsWith(variables['Build.SourceBranch'], 'refs/tags/v') }}
isFork: ${{ eq(variables['System.PullRequest.IsFork'], 'True') }}
isPR: ${{ eq(variables['Build.Reason'], 'PullRequest') }}
isTrustedCode: ${{ eq(variables.isFork, 'False') }}
isScheduled: ${{ eq(variables['Build.Reason'], 'Schedule') }}
isTrustedCI: ${{ and( eq(variables.isFork,'False'), eq(variables.isPR,'False'), eq(variables.isScheduled,'False') ) }}
and the debug-vars.yaml checks the values from vars/global.yaml with this code:
steps:
- bash: |
echo ""
echo "---------"
echo "Debugging"
echo "---------"
echo "isMain: ${{ variables.isMain }}"
echo "isProduction: ${{ variables.isProduction }}"
echo "Build.SourceBranch: ${{ variables['Build.SourceBranch'] }}"
displayName: Debug - Branch Variables
but when I run the CD pipeline from the main branch, the Build.SourceBranch is populated and the "isMain" is not, any idea why?
---------
Debugging
---------
isMain:
isProduction:
Build.SourceBranch: refs/heads/main
Finishing: Debug - Branch Variables