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
2 Answers
Reset to default 0You check the rest api for builds: Build - Definitions
- Create a new build to your Github repo and read repository settings: Definitions - Get, Definitions - BuildRepository.
- 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.
Make sure az-devops is installed:
az extension add --name azure-devops az devops login --anization $
list the team projects in Azure DevOps using
$projects = & az devops project list --anization $ | ConvertFrom-Json
list the pipelines in each project using
$pipelines = & az pipelines list --project $project --anization $ | ConvertFrom-Json
fetch the json payload holding the current build definition
$jsonConfig = & az pipelines show --name $build --project $project --anization $ | ConvertFrom-Json
from the returned json remove the
authoredBy
andcreatedDate
propertiesfrom 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.
- 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
- 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
本文标签:
版权声明:本文标题:How to programmatically update lots of existing Azure DevOps Pipelines (yml) to use newly migrated GitHub Repos? - Stack Overflo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741013179a2324153.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论