admin管理员组

文章数量:1266070

I need to update multiple existing Azure DevOps pipelines that currently point to Azure Repos repositories and reconfigure them to use the newly migrated GitHub repository instead. The pipelines are already set up and linked to the old repo, but I want to migrate them to GitHub while preserving all pipeline settings and configurations.

In other words, I think a method to query all pipelines currently connected to a given azure repo (e.g. CI and CD but maybe others), and programmatically change the referene to its equivalent in github, including connection to it.

I'd like to do this programmatically because It's over 800 of them.

Thank you!

I need to update multiple existing Azure DevOps pipelines that currently point to Azure Repos repositories and reconfigure them to use the newly migrated GitHub repository instead. The pipelines are already set up and linked to the old repo, but I want to migrate them to GitHub while preserving all pipeline settings and configurations.

In other words, I think a method to query all pipelines currently connected to a given azure repo (e.g. CI and CD but maybe others), and programmatically change the referene to its equivalent in github, including connection to it.

I'd like to do this programmatically because It's over 800 of them.

Thank you!

Share Improve this question edited Feb 28 at 3:21 Markus Meyer 3,96710 gold badges26 silver badges43 bronze badges asked Feb 28 at 0:15 JASON HEIDENTHALJASON HEIDENTHAL 1 3
  • devops.stackexchange is a better place to ask about devops tasks and tools. – tevemadar Commented Feb 28 at 0:41
  • @tevemadar with a CI/CD collective on StackOverflow, this place is an equally good place to ask this question. – jessehouwing Commented Feb 28 at 13:15
  • @jessehouwing I find the existence of that collective disruptive. – tevemadar Commented Feb 28 at 13:47
Add a comment  | 

2 Answers 2

Reset to default 0

You check the rest api for builds: Build - Definitions

  1. Create a new build to your Github repo and read repository settings: Definitions - Get, Definitions - BuildRepository.
  2. Update the BuildRepository section for your old builds: Definitions - Update

Example of a rest api request to update exiting build settings: Update build definition using Azure DevOps REST API in PowerShell

In case you used the GitHub Enterprise Importer, there is a rewire command to automatically update all build definitions.

gh extension install gh/gh-gei
gh extension install gh/gh-ado2gh
gh ado2gh rewire-pipeline ...

For a similar change that didn't support gei, I used the following process:

I'm using a az-cli and powershell to update the build definitions. The full script is IP, but I can explain the process.

  1. Make sure az-devops is installed:

    az extension add --name azure-devops
    az devops login --anization $
    
  2. list the team projects in Azure DevOps using

    $projects = & az devops project list --anization $ | ConvertFrom-Json
    
  3. list the pipelines in each project using

    $pipelines = & az pipelines list --project $project --anization $ | ConvertFrom-Json
    
  4. fetch the json payload holding the current build definition

    $jsonConfig = & az pipelines show --name $build --project $project --anization $ | ConvertFrom-Json
    
  5. from the returned json remove the authoredBy and createdDate properties

  6. from the returned json replace the repository property with one that is reconfigured against GitHub.

Note: The easiest way to find the properties to change, edit one pipeline from Azure DevOps to GitHub and then diff build definitions. You need to apply the same changes for each build definition.

  1. Query the service connection id from the Azure DevOps Project:
    $result = & az devops service-endpoint list --project $project --anization $ | 
        ConvertFrom-Json | 
        Where-Object { $_.name -like $name } |
        Select-Object -ExpandProperty id
    
  2. Write the json to disk and call the update API for the build definition:
    $jsonConfig | set-content update.json -Force
    $apiPath = "/$project/_apis/build/definitions/$buildId"
    $apiVersion = "7.0"
    
    $result = az devops invoke --area build --resource definitions --route-parameters definitionId=$jsonConfig.id project="$project" -- $ --api-version $apiVersion --http-method PUT --in-file update.json
    

本文标签: