Reputation: 4282
I'm trying to set up a pipeline in Azure.
On pull-request a build validation triggers the pipeline and all stages and jobs are triggered.
After the merge, all jobs are skipped.
After the merge of the pull request, I would expect stage B
to be triggered
What am I missing so pipeline triggers correctly on merge?
trigger:
branches:
include:
- master
stages:
- template: 'main.yml'
stages:
- stage: 'A'
condition: startsWith(variables['build.reason'], 'PullRequest')
jobs:
- job: A
steps:
- script: echo A
- stage: 'B'
jobs:
- job: 'B'
steps:
- script: echo B
Upvotes: 0
Views: 531
Reputation: 4282
I found the issue and applied suggestions from @bright-ran-msft
Stage A
and B
are implicitly linked. Since stage A
was not triggered on the merge, stage B
would not start either.
Instead of using condition
, it is required to use if
stages:
- ${{ if eq( variables['build.reason'], 'PullRequest') }}:
- stage: 'A'
jobs:
- job: A
steps:
- script: echo A
- stage: 'B'
jobs:
- job: 'B'
steps:
- script: echo B
Upvotes: 1
Reputation: 13534
The trigger feature only works for the whole pipeline and not for an individual stage/job in the pipeline.
Normally, we use the different trigger types (CI/PR
, resources
) and filters (branches
, paths
, tags
) to define when the pipeline should be triggered.
In the pipeline, we generally specify conditions to a stage, job or step to define when the this stage, job or step should be run or not. The conditions will be verified after the pipeline has been triggered.
To specify conditions, you can use one of the following ways:
Upvotes: 1