Léo Coco
Léo Coco

Reputation: 4282

Azure pipelines - Stages are skiped despite no conditions

I'm trying to set up a pipeline in Azure.

Actual behavior

On pull-request a build validation triggers the pipeline and all stages and jobs are triggered.

After the merge, all jobs are skipped.

Expected behavior

After the merge of the pull request, I would expect stage Bto be triggered

Question

What am I missing so pipeline triggers correctly on merge?

azure.pipelines.yml

trigger:
  branches:
    include:
      - master 
stages:
  - template: 'main.yml'

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

Answers (2)

Léo Coco
Léo Coco

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.

Solution

Instead of using condition, it is required to use if

Example

 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

Bright Ran-MSFT
Bright Ran-MSFT

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

Related Questions