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.
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.
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.