3

I'm in the process of migrating from an on-premise TFS instance to VSTS. I have a lot of build pipelines (vNext build definitions) that were migrated to VSTS, but now I have to update them all to use a specific Agent.

There is no option available in the UI nor in the commandline client.

Am I missing an option available to me so I can update them all at once?

3
  • medium.com/@MRiezebosch/… I've pinged Manuel to put the scripts live. Aug 15, 2018 at 20:52
  • 3
    Not sure why this was put on hold. Unless you are aware of the availability of the REST API, there is no simple way, findable by a user, to fix the CI/CD pipelines. Making this a very valid question. I feel the question was closed by people who do not know VSTS. Nor is the fact it was closed without further explanation/comments against the new code of conduct. @Mike-diehl only ahs 6 points to his name, a little curtesy would have been nice. Aug 16, 2018 at 7:40
  • 1
    Thanks Moderators for doing the right thing. Welcome @Mike-Diehl. Don't let this experience scare you away from Stack Overflow there are lots of people who want to help. Just make sure you explain what you've already tried an what docs you've already searched. In this case, the solution is hard to find. Aug 16, 2018 at 15:06

1 Answer 1

6

Based on the migration work I did with Manuel (referred to the post Jesse mentions), I have made some scripts available that get the TFS queues and then use that for updating the VSTS build definitions.

  • Read-QueuesFromTfs.ps1
  • Repair-BuildDefinitions.ps1

Both scripts require a parameters PersonalAccesToken - One is a PAT for the VSTS account you are targeting and one for targeting the TFS environment.

First script helps you get a queues.json file that holds all TFS Queues. Second script iterates the VSTS projects you are targeting for updating the build definitions. Scripts should be quite self-explanatory.

# Get all queues and based on previous names get the id's
    (Invoke-RestMethod `
            -Uri "https://$account.visualstudio.com/$_/_apis/distributedtask/queues" `
            -Headers @{Authorization = "Basic $auth"; Accept = "application/json; api-version=3.2-preview" } `
            -Method Get `
            -ContentType "application/json" -Verbose).value | % { $vstsqueues[$_.name] = $_.id }

    # get all the builds
    $builds = (Invoke-RestMethod `
            -Uri "https://$account.visualstudio.com/$_/_apis/build/definitions" `
            -Headers @{Authorization = "Basic $auth"; Accept = "application/json; api-version=4.1-preview.6" } `
            -Method Get `
            -ContentType "application/json").value

        # get the full build definition
        $build = Invoke-RestMethod `
            -Uri $_.url `
            -Headers @{Authorization = "Basic $auth"; Accept = "application/json; api-version=4.1-preview.6" } `
            -Method Get `
            -ContentType "application/json" 

        # get queue
        $queuename = $tfsqueues[$_.queue.id]
        Write-Output "    queue name: $queuename"

        # update build
        $build.queue = @{ id = $vstsqueues[$queuename] }

        # post changes
        Invoke-RestMethod `
            -Uri $_.url `
            -Headers @{Authorization = "Basic $auth"; Accept = "application/json; api-version=4.1-preview.6" } `
            -Method Put `
            -ContentType "application/json" `
            -Body ($build | ConvertTo-Json -Depth 100 -Compress) | Out-Null
    }
}

Described in this file. https://github.com/JasperGilhuis/VSTS-RestAPI/blob/master/README.md#update-vsts-build-definitions-based-on-tfs-queues

Look that the Builds folder in the repository https://github.com/JasperGilhuis/VSTS-RestAPI/tree/master/Builds

1
  • 1
    Thanks Moderators for doing the right thing. Welcome @jasper. Don't let this experience scare you away from Stack Overflow there are lots of people who want to help. When you answer, make sure you include the relevant snippets when linking to external sources. Especially "young" users will automatically be flagged when the links to content ratio is bad. Aug 16, 2018 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.