meerkat
meerkat

Reputation: 1122

Conditionally setting parameter in yml file (Azure pipeline): VAR not updating

Problem

I want to set a parameter conditionally based on which branch triggered the pipeline. If the triggered branch was feature/automated-testing, I would like to set a parameter equal to "True". See the code below.

Parts of my pipeline.yml file looks like so:

trigger:
  branches:
    include:
      - feature/automated-testing

...

# Global variables for the pipeline
variables:
  - name: "triggerRepoName"
    value: "$(Build.SourceBranchName)"


stages:
  # common stage. Docker build, tag and push
  - stage: BuildDockerImage
    displayName: "Build docker image"
    variables:
     ...

    jobs:
      - template: /templates/pipelines/my-prject.yml@templates
        parameters:
          ${{ if eq( variables.triggerRepoName, 'feature/automated-testing') }}:
            runTests: "True"
          ${{ if ne(variables.triggerRepoName, 'feature/automated-testing') }}:
            runTests: "False"

Question

When I push from branch feature/automated-testing and ´echo´ the variable runTests in the Dockerfile, it is blank. Is there something wrong with my syntax in the conditional statement?

I believe the error is in the way the variable is set conditionally, and I have therefore chosen not to supply the Dockerfile nor the other .yml template .yml used.

Upvotes: 2

Views: 3101

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40849

Please change variables.triggerRepoName to variables['triggerRepoName']. It should solve your issue.

Upvotes: 3

Related Questions