Thursday 31 January 2019

Copying a Build Definition to Another Team Project in a Different Azure DevOps Organization

You can easily clone a build and create a new build definition in the same team project. This is useful when you have similar type of applications to be built. However, if you want to clone a build definition to another team project, or for that matter to a different Azure DevOps Organization, you cannot use the clone as it always creates it in the same team project. For task groups you can use import and export to get them copied over to a different team project or even to  a different team project in a different Azure DevOps organization. Let’s look at how to export and import a build definition from a team project into a different team project in a different Azure DevOps organization.

Prerequisites
  • If you have any variable group defined and used in source build make sure to crate the variable groups with same name in the target team project.
  • If any task groups are used export and import them to the new team project. There may be extensions that you may want to install for the target team project if it is a different Azure DevOps organization.
How to import and export build definition
With above prerequisites fulfilled, you can use export in builds tab to export a definition as a json file.
Then go to new team project and click new and import. If you do not have any build definitions you will not see the view shown below. Create a dummy build definition temporarily in that case.
After importing the build definitions you ma have to fix following items.
  • Agent pool – you have to select the relevant pools.
  • Fix source location and authorize to get source code.
  • Fix any service connections used in tasks.
Then if you try to save or save and queue the build you will run into below error.
The request specifies project ID <target project guid> but the supplied pipeline specifies project ID <source project guid>.


To fix this open the exported json file in a notepad and search for source project guid and replace it with target project guid. you do nt have to fix any other part of this file such as URLs referring the  source team project and Azure DevOps organization.
However, if you want to find the project guides before running into the errors you can do it using REST api call. Replace your Azure DevOps organization name and team project name in below url and run it in a browser to get the project Id. This way you can avoid the project Id error when trying to save imported build definition from a different team project.
https://dev.azure.com/yourorgname/_apis/projects/teamprojectname?api-version=5.0

No comments:

Popular Posts