Coder Social home page Coder Social logo

Comments (3)

ewingjm avatar ewingjm commented on August 24, 2024 1

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?

from development-hub.

ewingjm avatar ewingjm commented on August 24, 2024 1

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
          }
        }
      }
    }
  }

from development-hub.

tdashworth avatar tdashworth commented on August 24, 2024

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? 😄

from development-hub.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.