Open tdashworth opened 3 years ago
Hi @tdashworth. We were getting this a lot as well. In the end I added a retry to the Merge-SolutionMerge.ps1 script and it resolved it. I need to feed that change back into the sample here. Never got to the bottom of what's going on. Perhaps Azure DevOps is automatically linking the work item to the extract pipeline at the same time as we're trying to link the work item to the pull request?
I've spent some time this evening exploring this and my guess is when committing with a work item, ADO will auto-link it which might be the conflicting change.
Could you share your updated version if it's working well? 😄
Hi, @tdashworth. Sorry I've been slow to respond to this. I'm sure you've sorted something out yourself by now. This is what we've got. It's a little agricultural, but it works -
if ($solutionMerge.devhub_Issue.devhub_azuredevopsworkitemid) {
Write-Host "Linking pull request to work item $($solutionMerge.devhub_Issue.devhub_azuredevopsworkitemid)"
$success = $false
$attempt = 1
while (!$success) {
try {
$result = Invoke-RestMethod `
-Uri "https://dev.azure.com/$org/$project/_apis/wit/workItems/$($solutionMerge.devhub_Issue.devhub_azuredevopsworkitemid)?api-version=4.0-preview" `
-Headers @{ 'authorization' = "Bearer $env:SYSTEM_ACCESSTOKEN"; 'content-type' = 'application/json-patch+json' } `
-Method PATCH `
-Body (ConvertTo-Json -Depth 100 @(
@{
op = 'add';
path = '/relations/-';
value =
@{
rel = "ArtifactLink";
url = $($result.artifactId)
attributes = @{
name = "Pull Request"
}
}
}
)
)
$success = $true
}
catch {
if ($attempt -lt 3) {
Write-Warning "Failed to link pull request to work item on attempt $attempt of 3."
Start-Sleep -Seconds 5
$attempt++
}
else {
throw
}
}
}
}
}
Description Occasionally, the merge pipeline fails to link the related work item. This is not a massive issue as the commit is already made and the link can be made manually. I'm not sure why this is occurring as I don't know what changes happen in between what timeframe.
Steps to reproduce Follow the standard process for approving a merge. This merge did have manual activities and we are using the PR process.
Expected behaviour The work item to be linked and for no error to occur.