meerkat
meerkat

Reputation: 1122

Skipped pipeline stage in Azure devops

Problem

When the pipeline underneath is triggered, the Dev stage is not being run after Build and push.

enter image description here

The pipeline is triggered with a PR with develop as the target branch.

pipeline.yaml

trigger:
  branches:
    include:
      - master
      - develop

pr:
  branches:
    include:
      - develop

stages:
  # Frontend tests: Triggered by opening new PRs to develop or updating pr to develop.
  - stage: FrontEndTests
    displayName: "Frontend tests"
    condition: eq( variables['Build.Reason'], 'PullRequest') #  Trigger stage only for PullRequests
    jobs:
      - template: /templates/pipelines/npm-unit-tests.yml@templates
        parameters:
          triggerType: ${{ variables.triggerType }}

  # Common build triggered by push to master or develop
  - stage: BuildPush
    displayName: "Build and push"
    condition: ne(variables['Build.Reason'], 'PullRequest') # Don't perform stage if PR triggered pipeline
    variables:
      envName: "common"

    jobs:
      - template: /templates/pipelines/dockerbuild-dashboard-client.yml@templates
        parameters:
          displayName: "Build docker image"
          deploymentName: "docker_build_push"
          dependsOn: ""

  # Dev deploy stage
  - stage: dev
    displayName: "Dev"
    dependsOn: BuildPush
    condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/master'))
    variables:
      envName: "dev"

    jobs:
      - template: /templates/pipelines/webapprelease-dashboard-dev-client.yml@templates
        parameters:
          dependsOn: ""
          deploymentName: "publish_container_to_webapp"
          
  # Test deploy stage
  - stage: test
    displayName: "Test"
    dependsOn: BuildPush
    condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/develop'))

    jobs:
      - template: /templates/pipelines/webapprelease-dashboard-test-client.yml@templates
        parameters:
          dependsOn: ""
          deploymentName: "publish_container_to_webapp"

  # Prod deploy stage
  - stage: prod
    displayName: "Prod"
    dependsOn: test
    condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
    variables:
      envName: "prod"

    jobs:
      - template: /templates/pipelines/webapprelease-dashboard-prod-client.yml@templates
        parameters:
          dependsOn: ""
          deploymentName: "publish_container_to_webapp"

Question

Why is the Dev stage not run? It seems to me that the conditions for the dev stage are not met, but I cannot see why.

Upvotes: 10

Views: 13294

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40879

In your case succeded is evaluated as

With no arguments, evaluates to True only if all previous jobs in the dependency graph succeeded or partially succeeded.

And FrontEndTests was skipped thus while was evaluated as false.

Please change it to

  condition: |
    and(
    or
    (
      in(dependencies.FrontEndTests.result, 'Succeeded', 'SucceededWithIssues', 'Skipped'),
      in(dependencies.BuildPush.result, 'Succeeded', 'SucceededWithIssues', 'Skipped')
    ),
    ne(variables['Build.SourceBranch'], 'refs/heads/master'))

I tested this on this case and it works as above

pool:
  vmImage: 'ubuntu-latest'

stages:
- stage: build
  displayName: Build
  condition: eq( variables['Build.Reason'], 'PullRequest')
  jobs:
  - job: Build
    steps:
    - bash: echo "Build"
- stage: test
  displayName: Test
  condition: succeeded()
  jobs:
  - job: Test
    steps:
    - bash: echo "Test"
- stage: test2
  displayName: Test2
  condition: |
    or(
      in(dependencies.build.result, 'Succeeded', 'SucceededWithIssues', 'Skipped'),
      in(dependencies.test.result, 'Succeeded', 'SucceededWithIssues', 'Skipped')
    )
  jobs:
  - job: Test2
    steps:
    - bash: echo "Test2"

Upvotes: 15

Related Questions