0
votes

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

1

1 Answers

2
votes

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

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

You will fine more examples like this here