Peter Szekeli
Peter Szekeli

Reputation: 2800

Azure DevOps - Use parameter to set path trigger in yaml pipeline definition

I'd like to set up an Azure pipeline using yaml template. What I struggle with is the path triggers definition. I'd like the individual pipelines to start up, only if they actually differ from their earlier versions.

core.yaml is a generic template, which is used across the different projects.

parameters:
- name: projectPath
  type: string

trigger:
  branches:
    include:
    - master
    - feature/*
  paths:
    include: 
    - ${{ parameters.projectPath }} # this is the problematic part

steps:
  ... # restore, build, test, etc tasks are defined here

build.yaml files are defined for every project. They only extend on core.yaml and supply the required parameters:

extends:
  template: core.yaml
  parameters:
    projectPath: src/project1

Using the value ${{ parameters.projectPath }} fails as "Template expression is not allowed in the given context". Same occurs if I surround it with quotes.

Using the value $(parameters.projectPath) works, but it triggers even if I change a file outside the defined path.

I also tried using the actual values instead of a parameter (e.g. "src/project1"), but it also triggers for every change, even if I only touch the file "src/project2/foo.md".

The examples I saw did not use triggers within a template. But normally I got a syntax error when the pipeline is triggered (e.g. unexpected value) when I misplaced a node. So it's just my expectation that it should work.

Any suggestions?

Upvotes: 2

Views: 2576

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40603

This is not possible, because this part

trigger:
  branches:
    include:
    - master
    - feature/*
  paths:
    include: 
    - ${{ parameters.projectPath }} # this is the problematic part

needs to be known on compilation time, but you provide parameter which is evaluated at runtime.

And this syntax $(parameters.projectPath) doesn't make any sense, and probably is evaluated to empy value and then everything is included into trigger.

Upvotes: 2

Related Questions