gitazure-devopsazure-pipelinesazure-repos

In Azure Pipelines, is there a way to disable CI on a branch with an open PR when hosted in Azure Repos?


We have a use case where our code is fully-hosted in Azure DevOps (Pipelines, Repos, et al). We need to build and deploy our "full" build/deploy process to deploy a serverless function. What we ideally want would be a single build/deploy process when a PR is open and updated. We have a build validation policy which we would like to ignore the Individual CI build when the PR accepts another push as Build Validation policies should supersede the trigger block.

Is there a way to accomplish this since the pr triggers aren't available to Azure Repos?

Repo Type: Azure Repos Git

# The pipeline will fail if a branch is not either 'main' or 'something/12345-something'
trigger:
  paths:
    exclude:
      - azure-pipelines-cleanup.yaml
      - docs
      - README.md

name: $(SourceBranchName).$(Rev:r)_$(Build.RequestedFor)

resources:
  repositories:
    - repository: pipeline
      type: git
      name: <Org Obscured>/infra-pipeline
      ref: feature/212242-pipeline-housecleaning # this is pipeline branch ref, should be main unless testing pipeline changes

# This extends a template from the central pipeline repo
extends:
  template: service-pipeline-template.yaml@pipeline
  parameters:
    appName: starter
    publishSdk: true

Build Validation setup

Result: Two builds, one Invididual CI, one PR automated triggered simultaneously Double triggered builds - Individual CI, and PR automated

Desired: Only the PR automated build.

This isn't an issue with a conditional expression per se unless there's a way to disable the trigger block outright while still running the full pipeline in PR. I don't imagine there's a way to run server-side git hooks in ADO.


Solution

  • I am afraid that there is no such method could disable CI trigger only when PR trigger exists.

    In Azure Devops , CI trigger and PR trigger are two independent triggers. If the trigger conditions are met at the same time, the pipeline will be triggered twice.

    Here are the trigger conditions of CI trigger and PR trigger.

    Howerver, there is a workaround could achieve your desired state.

    You could add [skip ci] in the commit message when you push changes.

    enter image description here

    Then the CI trigger will be skipped. And this commit will only trigger PR trigger Build.

    The following is the equivalent commit message

    [skip ci] or [ci skip]

    skip-checks: true or skip-checks:true

    [skip azurepipelines] or [azurepipelines skip]

    [skip azpipelines] or [azpipelines skip]

    [skip azp] or [azp skip]

    You can aslo submit the feature request in Our UserVoice site.