13

I'm trying to copy a release definition from one Azure Devops (VSTS) project to another. In the source project I'm able to export the release definition as a json file.

export release definition

But I'm not able to find a way to import this into the target project. I only get options to create new definitions.

create release definition

reggaemahn
  • 4,932
  • 5
  • 26
  • 53

6 Answers6

9

Since VSTS is Renamed/updated into Azure DevOps, there are some changes in the UI to find those option above.

For Importing

enter image description here

For Exporting

enter image description here

Regarding the addendum

All the build/Release definition came along with the single term called Pipeline. So there is no need to create a dummy release definition in order to import a new one. You can import a new release definition without having any dummy one.

Jayendran
  • 6,972
  • 4
  • 39
  • 80
  • 6
    I have to disagree with your point about not requiring a dummy Pipeline before importing one. I'm in the same position as @jeevs - I have a new Azure DevOps project into which I'm trying to import a Build Definition. However, because there are no existing BDs, the menu bar which includes the option to import doesn't appear. There seems to be no way to access the Import function without at least one BD already existing. – Philip Stratford Dec 17 '18 at 11:11
  • Any documentation on how a pipeline json looks like? Everywhere else a yaml file is used. – Marcus Jun 04 '19 at 17:07
  • @Marcus you can find the model of json from [here](https://docs.microsoft.com/en-us/rest/api/azure/devops/build/definitions/get?view=azure-devops-rest-5.0) which is nothing but get definition rest API – Jayendran Jun 05 '19 at 03:34
  • I concur with Philip - without an existing pipeline there appears to be no way to import. – Thierry Oct 15 '19 at 20:10
7

enter image description here

Go to Build and Releases and then Releases and there you will find an option. Click the + button and there is an option to import release definitions

Let me know if you need further help.

reggaemahn
  • 4,932
  • 5
  • 26
  • 53
noor
  • 102
  • 8
  • It worked great, thanks! It gives me a warning saying `Following properties in the release definition are not imported: Agent Queues, Deployment Groups, Deployment Group Tags, Approvals, Variable Groups and values of secret variables.` Any way around this? – reggaemahn May 09 '18 at 05:16
  • I dont know any way to surpass the development group and Agent Queue ..When you import , it does give you option to choose from dropdowns – noor May 09 '18 at 18:38
  • 5
    If you are in a project with no release definitions, you won't see this + button, you have to create a new blank release, save it, then when you go back you will see the button. – raterus Jun 27 '18 at 16:11
  • @raterus thank's... this info should be added to the answer – Jose May 08 '20 at 03:23
7

From reading the comments above the reason you are having issues with importing a Release Definition from a different VSTS/Azure DevOps origanization is because the Release Definition that you exported contains GUID references to objects that do not exist in the organization or project that you are importing the Release Definition into. So, you are going to have to roll up your sleeves and do some work in order to have a successful smooth and fully integrated Release Definition that you can use as a template. We are going to be using the REST API found here: https://docs.microsoft.com/en-us/rest/api/vsts/release/definitions/create?view=vsts-rest-4.1

Here is my technical answer and what I did to duplicate a Release Definition and created a template to be used numerous times:

  1. Export the Release Definition of your choice

  2. Format the JSON in some tool like https://jsonformatter.curiousconcept.com to make it more readable, and then save it in a text file like ReleasePipelineTemplate-Formatted.json

  3. I don't know what components you have defined in your Release Definition, but take a look around and see how GUIDs are used throughout. It might be helpful to create a release definition in order to find the GUIDs that you are going to have to replace.

  4. The GUIDs to find are SYSTEM_COLLECTIONID, SYSTEM_TEAMPROJECTID, SYSTEM_DEFINITIONID, BUILD_QUEUEDBYID

  5. Let us get some variables mentioned above from your build organization and project. In order to get these we need to print some environment variables during a regular build. So, please add a build step somewhere in the beginning of your CI build that adds a "Batch Script" step with the following command "C:\Windows\System32\cmd.exe" and argument "/c set". After the build is done, look into the logs at that build step and find the values for those variables. You will need those in the Release Definition.

  6. You should make a copy before we modify the json file. You should trim down the json file a bit by removing a few things like "createdOn", "modifiedBy", "modifiedOn". At the very bottom is "url" are 3 link. Those needs to modified with the Team Project ID GUID for example. This is just an example of places that need to be modified. Please inspect your own Release Definition.

  7. I'm going to assume you've made the necessary changes to your JSON file and ready to try to import it. Create a PowerShell script called 'CreateReleasePipeline.ps1' with the following script example.

$homeDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$VSTS_RestApiHost = "https://vsrm.dev.azure.com/yourpath/_apis"
$VSTS_PAT = "YOUR_PAT_TOKEN_HERE"
$headers = @{Authorization = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($VSTS_PAT)"))}
$relDefInfo = Get-Content "$homeDir\ReleasePipelineTemplate-Formatted.json"
Write-Host "Creating Release Pipeline..."
$createReleaseDef = "$($VSTS_RestApiHost)/release/definitions?api-version=4.1-preview.3"
$response = Invoke-RestMethod -Method Post -Uri $createReleaseDef -Body $relDefInfo -ContentType 'application/json' -Headers $headers
Write-Host "Create Release Pipeline done. Pipeline id: $($response.id)"
if ($response.id -gt 0) {
  Write-Host "Release definition: succeeded."
}
Write-Host $response.id
  1. Execute your script with '.\CreateReleasePipeline.ps1' and the output will look something like this:

.\CreateReleasePipeline.ps1
Creating Release Pipeline...
Create Release Pipeline done. Pipeline id: 71
Release definition: succeeded.
71
  1. Refresh your Release Pipeline web page and you should see your newly created Release Pipeline.

  2. You can go ahead and re-try until you are satisfied with your results.

I am using this REST API to put a Release Definition template into the source code repository so that I don't have to update 50+ and growing Release Pipelines when I make an adjustment to them. I can a REST API call check if a Release Definition exists, create it if it doesn't, update it if it is not up-to-date. All without having to cramp my hand having to update them manually or create a pipeline when a new get repo is created. I want to automate everything as much as possible. I want to change once or as few as possible and let the system update itself.

Please let me know if this helps.

Antebios
  • 1,373
  • 1
  • 10
  • 15
  • Hello the approach works for Creating build pipelines .When I use the same approach which you have mentioned , I get page not found . https://devops.azure.com/VSS/_apis/release/definitions?api-version=4.1-preview.3 : Page not found https://devops.azure.com/VSS/_apis/build/definitions?api-version=4.1-preview.3 : Works – Balakumar Ezhilmaran Nov 09 '18 at 12:22
  • Hello @Antebios . I am following the same steps which you mentioned .works fine . But were you able to set the Agent Pool in the json . In the exported definition json , I dont see a attribute like queue / pool . – Balakumar Ezhilmaran Dec 17 '18 at 09:02
7

If you don't see the import option, you can try creating a first empty pipeline

enter image description here

Once you have it, it enables the import option

enter image description here

Gabriel Castillo Prada
  • 2,619
  • 3
  • 17
  • 25
4

Leaving this here as an addendum to the accepted answer.

The accepted answer does work, but I should mention that my initial problem wasn't precisely solved by it.

Basically if you don't have any existing release definitions, there doesn't seem to be a way to import definitions. What I did was to create a 'dummy' definition and then follow what the accepted answer says. Creating at least one definition brings you to that screen otherwise you'll only get the screens I show in my question.

reggaemahn
  • 4,932
  • 5
  • 26
  • 53
  • Please note that the answer this is referring to is using the GUI to import a downloaded json file, which imports the release definition while stripping out references to another organization's users, agent queues, deployment groups, and other organization and team project specific objects. The other answer reveals that you will have to work around these issues and prepare the release definition json file before attempting an import. – Antebios Sep 26 '18 at 15:26
0

After export it generates json file save it in the local folder. And then go to the release or plus (+) button click on it and you can see inport option there click on it and select that json file. and thats it.....

niks
  • 346
  • 3
  • 9