Closed
Description
Description
We're using something like the following snippet for creating and auto linking a work item to a PR in the build pipeline. We're curious if there is a Azure Powershell command that achieves the same without adding "az" into the mix in the pipeline.
steps:
- powershell: |
Write-Host "Installing Azure CLI extensions..."
az extension add --name azure-devops
displayName: 'Install Azure CLI Extensions'
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
condition: always()
- powershell: |
Write-Host "Checking for associated work items..."
$workItems = az boards work-item relation list --id $(Build.BuildId) --query "[?rel=='System.LinkTypes.Hierarchy-Reverse'].target.id" -o tsv
if (-not $workItems) {
Write-Host "No associated work items found. Creating a new work item..."
$prTitle = az repos pr show --id $(System.PullRequest.PullRequestId) --query "title" -o tsv
$workItem = az boards work-item create --title "$prTitle" --type "Bug" --description "This work item was created because no work item was associated with build $(Build.BuildId)." --assigned-to "$(Build.RequestedFor)" --area "Outlook Web\Native Host" --query "id" -o tsv
Write-Host "Linking work item $workItem to the pull request..."
az repos pr work-item add --id $(System.PullRequest.PullRequestId) --work-items $workItem
} else {
Write-Host "Associated work items found: $workItems"
}
displayName: 'Check, Create, and Link Work Item'
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
condition: always()