Sar
Sar

Reputation: 299

Pull Request Build and skip other stages

I am using multi stage YAML pipelines in Azure DevOps and Where I build in one stage and deploy the artifact to other stages. I have setup a Pull Request build and whenever a new code is pushed all stages in the pipeline are running, which is not desirable.

what i want is whenever a new code is pushed to any branch i want to run the build stage and skip the deploy stages. This option is available by default classic pipeline as build and release are a seperate component earlier

Upvotes: 4

Views: 3275

Answers (2)

Krzysztof Madej
Krzysztof Madej

Reputation: 40939

You need to add condition to skip stage/step for pull request builds. You can do using this:

ne(variables['Build.Reason'], 'PullRequest')

For example:

- stage: B
  condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
  jobs:
  - job: B1
    steps:
      - script: echo This is not PR trigger

You will find more examples like this here

Upvotes: 9

Davi Ruiz
Davi Ruiz

Reputation: 120

Another example supporting multiple build reasons:

condition: and(succeeded(), not(in(variables['build.reason'], 'PullRequest', 'Schedule')))

Upvotes: 0

Related Questions