Search code examples
azure-devopsazure-pipelines

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


Solution

  • 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