0

Is it possible to filter a github user to not trigger a pipeline if a commit is pushed?

E.g. if a bot-user pushes some changes, the git-pipeline should not be triggered. I only find information to trigger changed files or branch-names.

BendEg
  • 20,098
  • 17
  • 57
  • 131
  • There's no such out-of-box feature. Once we enable the CI trigger, the pipeline will be triggered no matter who commit the change... For now the filter of CI trigger only supports [branches, paths and tags](https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#ci-triggers) but not committers. An alternative workaround should be adding one CMD/PS task to get the user ID, then we can fail the pipeline run at the first task or skip the following tasks to save the time. – LoLance Sep 30 '20 at 03:31

1 Answers1

0

Is it possible to filter a github user to not trigger a pipeline if a commit is pushed?

No, for now Azure Devops CI trigger only supports filters like Branches, Paths and Tags. It doesn't have filter for specific users, so the pipeline will always be triggered if there're changes committed.(No matter who pushes the commit)

Possible workaround:

One alternative workaround is to add PS task to filter the user and fail/complete the pipeline at that task, it would save much time. In such scenario, the pipeline will be triggered but it will finish immediately.

We can use git log --format='%ae' $(Build.SourceVersion)^! command to get the Id of the user who makes the commit. $(Build.SourceVersion) represents commit id.

In my test, a user in github organization has the Id format like xxxxxx+accountName@users.noreply.github.com.(You can use the command to find the Id of the user you want to filter first)

Simple example:

trigger:
- master

pool:
  vmImage: 'windows-latest'

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      $Id = (git log --format='%ae' $(Build.SourceVersion)^!)
      if ($Id -like "5xxxxxx6+lancexxx@users.noreply.github.com")
          {
            Write-Host "##vso[task.complete result=Failed;]"
          }
      if ($Id -like "xxx")
          {
            Write-Host "##vso[task.complete result=Failed;]"
          }

- task: CmdLine@2
  inputs:
    script: |
      echo Hello world
...

We can add a PS task at the first of pipeline, it would be used to filter the specific user. The task would fail if the author of the pushed commit is someone 5xxxxxx6+lancexxx@users.noreply.github.com.

You can use conditional steps to skip the following tasks if you don't want to fail the pipeline run, so the pipeline run will report succeed and it won't take much time. See conditional steps.

LoLance
  • 25,666
  • 1
  • 39
  • 73