I'm trying to add an optional set of parameters when the build running is not on the master branch. The idea is that azure-pipelines-template-variables-private.yml overrides just some of the parameters contained in the group.
This is my template file:
stages:
  - stage: "Tests"
    variables:
      - group: MyLibrary
    ${{ if ne(variables['Build.SourceBranchName'], 'master') }}:
      - template: azure-pipelines-template-variables-private.yml
This returns the error "Expected a mapping"
Without the if block the behaviour is as expected - the parameters are overwritten. I'm struggling to understand how if blocks work. The docs show how to use variables with Group and variables with templates - but not both together. Though it seems to work together, so I would expect the if statement to work.
Edit: For information I'm including the variable template contents:
variables:
  - name: MyVar1
    value: 'TEST-$(Build.BuildId)'
  - name: MyVar2
    value: '/Builds/$(BUILD.BUILDID)'
I tested the script below and it works well. Hope this helps you :
- stage: build
  jobs:
  - job: run_build
        
    pool:
      vmImage: 'Ubuntu 16.04' 
    variables:
    - group: xxx
    - ${{ if ne(variables['Build.SourceBranchName'], 'refs/heads/master') }}:
      - template: var.yml
    steps:      
      - script: echo ${{ variables.test }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With