Reputation: 3811
I'm looking for a way to retrieve the information contained in the 'Development' section of a ticket (Task, Bug), more specifically the 'Integrated in Build' link value, to be used in a query:
Running this query returns nothing (loads of these work items contain valid links set in 'Integrated in Build'). If I remove the 'Integrated in Build' link field, I do get a list of work items.
Any help appreciated.
Azure Devops, 2019 on prem.
Upvotes: 2
Views: 2655
Reputation: 1937
I had a similar issue. What you could do is install the Wiql Editor Plugin for Azure DevOps, which is not an official plugin from Microsoft, but it is crazy helpful nonetheless.
When you use this plugin, you could just put together your query using normal means, i.e. the graphical query editor and then click Edit query wiql
, then the full and correct WIQL query pops out. For me there was also a field that I was unsure how to get it, but that solved my problem right away. In the end the one field causing me problems came out as Custom.IntegratedInRelease
.
Also, when this plugin is installed it gives you a WIQL playground, where you can play around and put together WIQL queries, there is even a built-in validation + autofill.
Check it out in the market place: https://marketplace.visualstudio.com/items?itemName=ottostreifel.wiql-editor
Upvotes: 0
Reputation: 19371
The first thing that needs to be clear is that the Integrated in Build
field you selected in the query is not the valid build links in Development.
In addition, query gets work items, and cannot return Development link information.
Upvotes: 0
Reputation: 15998
You can not use Integrated in Build
link type in work item queries because this link not to a work item. In work item queries you can use only filters to work item links and fields. In our project on Azure DevOps Services we add custom PowerShell step to CI builds. This steps adds a build number into Integration Build
field of work items linked in GIT commit:
$user = ""
$token = "$(System.AccessToken)"
$teamProject = "$(System.TeamProject)"
$orgUrl = "$(System.CollectionUri)"
$buildDefinitionName = "$(Build.DefinitionName)"
$buildNumber = "$(Build.BuildNumber)"
$repoName = "$(Build.Repository.Name)"
$bodyWorkItemInt = "[{op: `"add`", path: `"/fields/Microsoft.VSTS.Build.IntegrationBuild`", value: `"{value}`"}]"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$uriSearchCommit = "$orgUrl/$teamProject/_apis/git/repositories/$repoName/commits?api-version=5.1&searchCriteria.toCommitId={commitId}&searchCriteria.fromCommitId={commitId}&searchCriteria.includeWorkItems=true"
$last_commit = & git show --format=%H HEAD
Write-Host $last_commit
if ($last_commit.Count -gt 0)
{
$uriSearchCommit = $uriSearchCommit -replace "{commitId}", $last_commit[0]
Write-Host $uriSearchCommit
$resultCommit = Invoke-RestMethod -Uri $uriSearchCommit -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
if ($resultCommit.count -eq 1)
{
if ($resultCommit[0].value[0].workItems.Count -gt 0)
{
foreach ($workItem in $resultCommit[0].value[0].workItems)
{
Write-Host "Work item:" $workItem
$resultWorkItem = Invoke-RestMethod -Uri $workItem.url -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$int_value = $buildDefinitionName + "_" + $buildNumber
if ($resultWorkItem.fields.'Microsoft.VSTS.Build.IntegrationBuild' -ne $null)
{
if ($resultWorkItem.fields.'Microsoft.VSTS.Build.IntegrationBuild'.Contains($buildDefinitionName))
{
Write-Host "Work item contains the label:" $buildDefinitionName
$int_value = ""
}
else
{
$int_value += ";" + $resultWorkItem.fields.'Microsoft.VSTS.Build.IntegrationBuild'
}
}
if ($int_value -ne "")
{
$bodyWorkItemInt = $bodyWorkItemInt -replace "{value}", $int_value
$uriUpdateWI = "$orgUrl/$teamProject/_apis/wit/workitems/{id}?api-version=5.1" -replace "{id}", $resultWorkItem.id
Invoke-RestMethod -Uri $uriUpdateWI -Method Patch -ContentType "application/json-patch+json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $bodyWorkItemInt
}
}
}
}
}
Then you can search your build number in Integration Build
field with a work item query.
Upvotes: 4