mark
mark

Reputation: 62736

Is it possible to query builds in Azure DevOps REST API using negative filters?

I am using the List Builds API to query for builds.

I was wondering if it was possible to ask for all the builds with the reason different from pullRequest, for example, without actually listing all the other reasons.

Upvotes: 0

Views: 658

Answers (1)

Hugh Lin
Hugh Lin

Reputation: 19391

Is it possible to query builds in Azure DevOps REST API using negative filters?

For this issue,it is impossible to use negative filters in azure devops rest api.

The parameters provided in the rest api are defined.There are no such parameters like negative filter in the given parameters. So if we use parameters like reasonFilter , we can only specify the filter values one by one, but not in the form like exclude.

To filtering out the builds with the reason different from pullRequest, besides specifying all the required reasons in the reasonFilter, you can also filter the return result of the rest api through the code.

For example with powershell script:

$url = 'https://dev.azure.com/{org}/{pro}/_apis/build/builds?api-version=5.1';

$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} -Method Get

$results = $response.value | Where {$_.reason -ne "pullRequest"} #|

Write-Host "results = $($results | ConvertTo-Json -Depth 100)"

Upvotes: 1

Related Questions