bjorkblom
bjorkblom

Reputation: 1959

Azure DevOps pipelines stages

I got a setup where I want to trigger the CI to build on each pull request to our Bitbucket Cloud repository. In the same setup I also have three different stages that's I would like to trigger manually when we would like to build the artefact to deploy to our environments.

The problem I got is that the pull request trigger doesn't trigger after I added stages in our build. This is how the configuration looks like:

pr:
  branches:
    include:
    - '*'

pool:
  vmImage: 'macos-latest'

stages:
- stage: CI
  displayName: 'Continues build'
  jobs:
  - job: C1
    steps:
      - template: azure-pipelines-ios.yml
        parameters:
          environment: 'ci'
      - task: PublishBuildArtifacts@1
        
- stage: Test
  displayName: 'Building for Test'
  jobs:
  - job: T1
    steps:
      - template: azure-pipelines-ios.yml
        parameters:
          environment: 'test'
      - task: PublishBuildArtifacts@1

- stage: Stage
  displayName: 'Building for Stage'
  jobs:
  - job: S1
    steps:
      - template: azure-pipelines-ios.yml
        parameters:
          environment: 'stage'
      - task: PublishBuildArtifacts@1

I would like to trigger the CI stage build on each pull request. How do I do that?

Upvotes: 0

Views: 271

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40603

If you want to skip other stages for you should use condition:

pr:
  branches:
    include:
    - '*'

pool:
  vmImage: 'macos-latest'

stages:
- stage: CI
  displayName: 'Continues build'
  condition: eq(variables['Build.Reason'], 'PullRequest')
  jobs:
  - job: C1
    steps:
      - script: echo "Hello $(System.StageName)"
        
- stage: Test
  displayName: 'Building for Test'
  condition: ne(variables['Build.Reason'], 'PullRequest')
  jobs:
  - job: T1
    steps:
      - script: echo "Hello $(System.StageName)"

- stage: Stage
  displayName: 'Building for Stage'
  condition: ne(variables['Build.Reason'], 'PullRequest')
  jobs:
  - job: S1
    steps:
      - script: echo "Hello $(System.StageName)"

Upvotes: 2

Related Questions