I also experimented with queries and i've been able to create query in
ADO which list tasks that are in "Done" state but i can't find a way
to get query result through REST api to Jenkinsfile. Any help with
that?
You can use the Powershell script to call the rest api, try this script(I use this rest api):
$token = "xxx"
$url="https://dev.azure.com/YourOrgName/YourProjectName/_apis/wit/wiql?api-version=5.1"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$JSON = @'
{
"query": "SELECT [System.Id],[System.Title],[System.State] FROM workitems WHERE [System.TeamProject] = @project AND [system.WorkItemType] = 'Task' AND [System.State]='Done' "
}
'@
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -Body $JSON -ContentType application/json
Write-Host "result = $($response | ConvertTo-Json -Depth 100)"
It will return all the WorkItems whose Type=Task
and State=Done
with their corresponding IDs and Urls.
You should enter your own PAT in $token
, and replace the YourOrgName
and YourProjectName
with your own Azure Devops OrganizationName and ProjectName.
As for how to call PS script in jenkinsfile, you can check Microsoft PowerShell Support for Pipeline and Executing powershell command directly in jenkins pipeline.
Edit1:
In web portal I have these wits:

Then in Postman I use body like this:

{
"query": "SELECT [System.Id],[System.Title],[System.State] FROM workitems WHERE [System.TeamProject] = @project AND [system.WorkItemType] = 'Task' AND [System.State] = 'Done'"
}
Response:
