You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将多VSTS实例的构建与发布定义迁移至同一实例?

Hey there! Since you're new to Azure DevOps (formerly VSTS), let’s walk through a clear, step-by-step process to migrate your build and release definitions from multiple instances into your target one. I’ll cover both manual methods (perfect if you only have a few definitions to move) and automated approaches (way better for large-scale migrations):

Manual Migration (Best for Small Number of Definitions)

If you’re dealing with just a handful of build/release definitions, this hands-on approach works great:

  1. Export your source definitions

    • Log into your source VSTS instance, then navigate to Pipelines > Builds (for build definitions) or Pipelines > Releases (for release definitions)
    • Find the definition you want to migrate, click the ... menu in the top-right corner, and select Export
    • Save the downloaded .json file somewhere easy to find
  2. Tweak the exported JSON file
    This is a critical step—you need to update references to match your target instance:

    • Replace all instances of your source organization/project URL/ID with the target’s values (you can find the target project ID in Project Settings > Overview)
    • Check for references to service connections, variable groups, or agent pools: make sure these exist in the target instance, or update the names to match what’s already there
    • Adjust any source code path references if your target instance’s repository structure is different
  3. Import into the target instance

    • Log into your target VSTS instance, go to the corresponding Pipelines section (Builds or Releases)
    • For builds: Click New pipeline > Import from JSON, then upload your modified file
    • For releases: Click New > Import release definition, then upload the JSON
    • Once imported, double-check all configurations (variables, triggers, service connections) to ensure everything is linked correctly
Automated Migration (Best for Large-Scale Migrations)

If you have dozens of definitions to move, using the Azure DevOps CLI will save you tons of time:

  1. Set up Azure DevOps CLI

    • Open your command prompt/PowerShell and run:
      az extension add --name azure-devops
      
    • Log into your source organization:
      az devops login --organization https://dev.azure.com/[your-source-org-name]
      
    • Set default source org and project:
      az devops configure --defaults organization=https://dev.azure.com/[your-source-org-name] project=[your-source-project-name]
      
  2. Export all build definitions

    • First, get a list of all build definition IDs:
      az pipelines build definition list --output json > build-defs.json
      
    • Use a PowerShell loop to export each definition to its own JSON file:
      $defs = Get-Content build-defs.json | ConvertFrom-Json
      foreach ($def in $defs) {
          az pipelines build definition show --id $def.id --output json > "build-def-$($def.id).json"
      }
      
  3. Batch-update the JSON files
    Write a simple PowerShell script to replace source org/project references with target values (this avoids editing each file manually). For example:

    $files = Get-ChildItem -Path . -Filter "build-def-*.json"
    foreach ($file in $files) {
        (Get-Content $file.FullName) -replace "https://dev.azure.com/[source-org]", "https://dev.azure.com/[target-org]" | Set-Content $file.FullName
        (Get-Content $file.FullName) -replace "[source-project-id]", "[target-project-id]" | Set-Content $file.FullName
    }
    
  4. Import to target instance

    • Switch your CLI defaults to the target organization and project:
      az devops configure --defaults organization=https://dev.azure.com/[your-target-org-name] project=[your-target-project-name]
      
    • Import each modified build definition with another loop:
      $files = Get-ChildItem -Path . -Filter "build-def-*.json"
      foreach ($file in $files) {
          az pipelines build definition create --json $file.FullName
      }
      
  5. Repeat for release definitions
    The process for releases is almost identical—just swap out the build commands with release-specific ones:

    • Export list: az pipelines release definition list --output json > release-defs.json
    • Export individual definitions: Use az pipelines release definition show --id [def-id]
    • Import: Use az pipelines release definition create --json [file-path]
Critical Pre-Migration Checks

Before you start moving anything, make sure these dependencies are in place in your target instance:

  • Service connections (Azure, GitHub, etc.) that your build/release definitions rely on
  • Variable groups with matching names and values
  • Agent pools (or use the default hosted pools if your definitions don’t require custom agents)
  • Source repositories (mirror or import your code to the target instance first—definitions can’t build code that doesn’t exist there!)

Always run a test build or release after migrating to catch any missing configurations or path issues. And double-check that you have Edit permissions for pipelines in both your source and target instances—you’ll need them to export and import definitions.

内容的提问来源于stack exchange,提问作者PRAVEEN PDBR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:58:45