51

I have a couple of CI pipelines that I'm using in Azure DevOps to build some Xamarin apps and I want to create a new one that merges the functionality of the two existing ones. Is there a way to copy or clone an existing pipeline so that I can make changes to the new pipeline without impacting the existing pipelines?

I saw that I can export a pipeline to a JSON file and then import it back in. All of the id values in the JSON file are GUID. Will the import process create new GUIDs or will importing the JSON file overwrite the existing pipeline.

7 Answers 7

58

UPDATE February 11th, 2020

Not sure if this is a super-recent change, but you can now again easily clone an existing pipeline. From Pipelines, click on the pipeline you want to clone. On the page where the build history is shown, Clone has been moved to the ellipsis menu on this page.

enter image description here

5
  • This is the old interface; I assume you have not updated to the new one
    – r3plica
    Commented Feb 27, 2020 at 20:57
  • 2
    I still see this version in April 2020 Commented Apr 5, 2020 at 19:07
  • 1
    @r3plica it's still there, they moved it though so it took me a second to find it too. Click on your pipeline and when you see "Edit | Run pipeline | ...", click on those ellipses. Commented Apr 30, 2020 at 22:05
  • I have admin rights on for my org, and I don't see most of those settings. Could it be related to the type of pipeline? Commented Oct 9, 2020 at 15:49
  • 1
    Hello, Is there any method to copy multiple CI/CD pipelines at a time? Any method to copy the root folder where multiple pipelines are included.
    – Antony
    Commented Feb 2, 2023 at 5:09
41

Click on Pipelines -> Click on your Pipeline -> then click the ellipse in the upper right corner (three vertical dots) then click Clone.

Where to find the Clone option on a build

6
  • 31
    As of Feb 2020 the Clone option is no longer visible when opening the menu through ellipsis icon.
    – codeepic
    Commented Feb 5, 2020 at 10:24
  • 2
    @codeepic do you know where is it now? Also, I found that there is a "Import" button, but "Export" button does not exist...
    – kiripk
    Commented Feb 6, 2020 at 10:00
  • @kiripk - no - I couldn't find it - but I am using the YAML pipelines now and it's easy to set up generic pipeline and just copy the yaml file contents from the one you wanted to copy.
    – codeepic
    Commented Feb 6, 2020 at 14:23
  • 4
    @codeepic Yeah, in the end I've also went that way. I've maybe did it not in the most beautiful way, but for others searching - you can go to your current pipeline that you want to clone, Edit → History tab and there select the last change to compare. You can save the provided JSON and then Import it. Voilà, cloned successfully.
    – kiripk
    Commented Feb 6, 2020 at 15:04
  • April 2021 - I just used the clone option on AzDO using these steps. Not sure why they hid it away from the edit/save controls
    – Ian Yates
    Commented Apr 19, 2021 at 9:46
21

UPDATE Feb 2020

Clone is not available anymore. However you can create a new pipeline based on an existing yaml file which is basically cloning.

Pipelines -> New Pipeline -> Configure (3rd page of the wizard) -> Select "Existing Azure Pipelines YAML file"

There you can select the branch and the file you want to use.

4
  • I've seen this option. Just tell me one thing - if I make a new pipeline and select existing Azure pipeline yaml in configuration step - does it copy the yaml file, so edits in one pipeline won't affect the other or do 2 pipelines now point to one yaml file?
    – codeepic
    Commented Feb 7, 2020 at 0:04
  • 1
    @codeepic it does create a new file. Original is untouched.
    – Losó Adam
    Commented Feb 8, 2020 at 9:35
  • 4
    Sadly, this does not copy the variables set in the pipeline. If you have 14 variables like we do, this is a lot of work to set up for each pipeline.
    – Drak
    Commented Apr 3, 2020 at 7:21
  • @LosóAdam Why would it create a new yaml file? It uses the yaml file from your repository, the one you have selected. As far as I can see, it just uses the existing one, and does not create a new yaml file.
    – Drak
    Commented Apr 3, 2020 at 7:27
3

Update: As per Microsoft 07-05-2022

For YAML: Go to pipeline details for your pipeline, and choose Edit. Copy the pipeline YAML from the editor, and paste it into the YAML editor for your new pipeline. enter image description here

For Classic:

Navigate to the pipeline details page for your pipeline. select Clone.

enter image description here

2

I know it is too late but easy way around by official document.

Hope that would help some.

2
  • This is for non-yaml pipelines.
    – Drak
    Commented Apr 3, 2020 at 7:52
  • Correct @Drak and if you wanted to clone the existing YAML based pipeline you can just make another copy of YAML and create a new pipeline which is straightforward. Commented Apr 15, 2020 at 11:29
1

So since Microsoft decided in all its wisdom to remove the "Clone" option from Yaml pipelines (because it would confuse users) I've decided to write a new extension with which you can clone Yaml pipeline definitions again. This might be needed since you can still use variables and triggers in the pipeline definition instead of the yaml file and we're using a lot of those for example. So to save you the hassle of having to rewrite everything manually, here's the Copy Pipeline Azure DevOps extension for Azure DevOps Server 2020+ or Azure DevOps Cloud:

https://marketplace.visualstudio.com/items?itemName=tun.ClonePipeline

have fun...

0

If you want to use existing stage in another pipeline, do following.

  1. Open the stage 2.Click on three dots at right side of it and select 'Save as template'. 3.In another pipeline, while adding stage, just search with name given at step2.

Not the answer you're looking for? Browse other questions tagged or ask your own question.