Cloning a project through the REST API?

Is it possible to clone a project through the REST API?

i have successfully created a project, through the POST command listed on this page, but looking at the fields of the projects resource i can’t see how to do this through the API.

I see the priviledges for cloning a project have changed in 2.5 - i was hoping this is now possible.

Thanks in advance.

Alternately could you please indicate how to do this with the current API ? I’ve tried the following:

  • Get the variable set from the base template project

  • Put this to the variable set of the new projects

  • Get the deployment processes of the base template project

  • Put this to the variable set of the new projects

Both of these result in an 500 error (Internal Server Error)

I note that in the doco for the API e.g https://github.com/OctopusDeploy/OctopusDeploy-Api/wiki/DeploymentProcesses

the “Steps” Resource is not described - so i don’t know what i’m providing that may cause the server to fall over.

I’m very much an Octopus newbie - hope I’m not doing something obviously wrong !

Hi Alister,

Yes, this is possible, it should be quite straightforward.

Normally, to create a project you invoke:

POST /api/projects

With all of the project info in the body. To clone an existing project, send exactly the same body, but add the ID of the project to clone in the URL:

POST /api/projects?clone=projects-123

If you need any help forming up the body of the request (will be some JSON along the lines of {"Name": ..., } you can use e.g. the Chrome dev tools to see an example when using the UI. Or, post any questions here and we’ll be happy to help out.

Cheers,
Nick

Cheers Nick - I finally noticed this in json returned from the top level api GET.

I’m waiting for the next release to be installed at our company, and the permissions to change to use the clone interface.

As an aside I don’t think this is in the documentation, and, as mentioned above, neither is the Steps JSON (which links back to the top level API documentation page). If I can find the write page to edit I might put in a pull request for it

Are there any plans to add the Clone option to the Client API or Octo.exe? It would be great to have the option in these Tools to avoid having one more dependency to manage in the build/deployment process.

Hi Mathias,

Thanks for getting in touch. We have a uservoice request for that feature. http://octopusdeploy.uservoice.com/forums/170787-general/suggestions/6469618-add-support-to-octo-exe-to-clone-projects

As for a way to do this from the Client API, let me ask the developers if there’s a way to do this with the current client version and get back to you on this.

Thanks!

Dalmiro

Det gick inte att leverera meddelandet till följande personer eller distributionslistor:

mathas.olausson@solidify.semailto:mathas.olausson@solidify.se
Det gick inte att hitta mottagarens e-postadress i mottagarens e-postsystem. Det här meddelandet kommer inte att skickas igen automatiskt. Kontrollera e-postadressen och försök att skicka meddelandet igen manuellt, eller lämna följande text till systemadministratören.


Skickat av Microsoft Exchange Server 2007

Diagnostisk information för administratörer:

Genererande server: Transcendentgroup.local

mathas.olausson@solidify.se
#550 5.1.1 RESOLVER.ADR.RecipNotFound; not found ##rfc822;mathas.olausson@solidify.se

Ursprungshuvuden:

Received: from smtp305.stejtech.net (192.168.104.118) by
mail.transcendentgroup.com (192.168.104.243) with Microsoft SMTP Server (TLS)
id 8.3.389.2; Thu, 22 Jan 2015 20:05:01 +0100
X-Spam-Status: No, score=0.441 tagged_above=-1000 required=4.5
tests=[DKIM_SIGNED=0.1, FROM_LOCAL_HEX=0.331, HTML_MESSAGE=0.001,
SPF_PASS=-0.001, T_DKIM_INVALID=0.01] autolearn=disabled
X-Spam-STAY-ID: v=2.0 cv=LswQOwhc c=1 sm=0 a=bnjrdiVAt+2QeRovbCPQzg==:17
a=9DTuHKedAAAA:8 a=YNv0rlydsVwA:10 a=RyxiuZ0eAAAA:8 a=PaW8tZoyAAAA:8
a=Tqz4KAq2xwgi1W5VG60A:9 a=QEXdDO2ut3YA:10 a=SSmOFEACAAAA:8 a=_W_S_7VecoQA:10
a=p403mkujtbAA:10
Received: from postcard.entp.com (postcard.entp.com [23.235.226.122]) (using
TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate
requested) by smtp305.stejtech.net (Postfix) with ESMTPS id A8B7E18A135C for
mathas.olausson@solidify.se; Thu, 22 Jan 2015 20:04:56 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tenderapp.com; s=sentry;
h=List-Post:List-Unsubscribe:List-Id:List-Help:List-Archive:List-Subscribe:Content-Type:Mime-Version:Subject:References:In-Reply-To:Message-Id:To:From:Date; bh=5xzv7uQEy+F4z/vPkXTGGSG+lC+Nm7bXmX3TSwBg1uM=;
b=G0T5O3BP+27Rxqhbpj47g0xt2DR3vx/75Ma7pY8/LMfl26NkU2RdyC91E3ivKw5E+6AEFIF7SoZ9wTvMkCDjj4R2QHUonVzsnDYNCzVFX+icuv8VV7W6OXcNjXmSkDzz23UfbY38xGMA08360yUN9n8mT8L5MpFnSggIzYdlSOWMswqvU6KjVL8NUiivCU4+Nsva9Zd7cVzOeU1C2aUrK7yOMCfAnWGC4M6eK+sFakKcfGXC+J2t+EFdcKLJherkPx5GJdUuTpnaYEEe80lyZpCo0JCD5A8yJFmQxXHlb6fkkEt5IdIFvbS8Yjb3AvRCgz3syMpfGsdz+ZHoVV3MHg==;
Received: from [192.228.96.5] (helo=tenderapp.com) by postcard.entp.com with
esmtpa (Exim 4.82) (envelope-from
tender2+d541ac88ed2712d4cc68043eb7fb5472d289410d2@tenderapp.com) id
1YEN3l-0007Bz-Rj for mathas.olausson@solidify.se; Thu, 22 Jan 2015 19:04:54
+0000
Date: Thu, 22 Jan 2015 19:04:53 +0000
From: =?utf-8?Q?Dalmiro_Gra=C3=B1as?=
tender2+d541ac88ed2712d4cc68043eb7fb5472d289410d2@tenderapp.com
To: mathas.olausson@solidify.se
Message-ID: 18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_7@octopus-deploy.tenderapp
In-Reply-To: 18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_6@octopus-deploy.tenderapp
References: 18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_6@octopus-deploy.tenderapp 18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_5@octopus-deploy.tenderapp
18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_4@octopus-deploy.tenderapp 18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_3@octopus-deploy.tenderapp
18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_2@octopus-deploy.tenderapp
Subject: Re: Cloning a project through the REST API? [Questions #2694]
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary=“mimepart_54c149d5a4c7f_3f253fc1f371d1401785a1”
X-Tender-Site: 18789
List-Subscribe: http://help.octopusdeploy.com/discussions/questions/2694-cloning-a-project-through-the-rest-api
List-Archive: http://help.octopusdeploy.com/discussions/questions
X-Pm-Keepid: true
List-Help: http://help.octopusdeploy.com
List-Id: Octopus Deploy <help.octopusdeploy.com>
List-Unsubscribe: http://help.octopusdeploy.com/discussions/questions/2694-cloning-a-project-through-the-rest-api
List-Post: tender2+d541ac88ed2712d4cc68043eb7fb5472d289410d2@tenderapp.com, http://help.octopusdeploy.com/discussions/questions/2694-cloning-a-project-through-the-rest-api
X-Tender: notification
Return-Path: tender2+d541ac88ed2712d4cc68043eb7fb5472d289410d2@tenderapp.com

untitled (7 KB)

untitled (342 Bytes)

Hi Mathias,

The following snippets will help you cloning a project using the Octopus.client:

C#

Powershell

Credit goes to our good friend Henrik from the dev team :slight_smile:

Hope that helps!

Dalmiro

Det gick inte att leverera meddelandet till följande personer eller distributionslistor:

mathas.olausson@solidify.semailto:mathas.olausson@solidify.se
Det gick inte att hitta mottagarens e-postadress i mottagarens e-postsystem. Det här meddelandet kommer inte att skickas igen automatiskt. Kontrollera e-postadressen och försök att skicka meddelandet igen manuellt, eller lämna följande text till systemadministratören.


Skickat av Microsoft Exchange Server 2007

Diagnostisk information för administratörer:

Genererande server: Transcendentgroup.local

mathas.olausson@solidify.se
#550 5.1.1 RESOLVER.ADR.RecipNotFound; not found ##rfc822;mathas.olausson@solidify.se

Ursprungshuvuden:

Received: from smtp10.stejtech.net (192.168.104.118) by
mail.transcendentgroup.com (192.168.104.243) with Microsoft SMTP Server (TLS)
id 8.3.389.2; Sun, 25 Jan 2015 05:49:37 +0100
X-Spam-Status: No, score=0.441 tagged_above=-1000 required=4.5
tests=[DKIM_SIGNED=0.1, FROM_LOCAL_HEX=0.331, HTML_MESSAGE=0.001,
SPF_PASS=-0.001, T_DKIM_INVALID=0.01] autolearn=disabled
X-Spam-STAY-ID: v=2.0 cv=C59rOHz+ c=1 sm=0 a=bnjrdiVAt+2QeRovbCPQzg==:17
a=9DTuHKedAAAA:8 a=YNv0rlydsVwA:10 a=NEAV23lmAAAA:8 a=PaW8tZoyAAAA:8
a=RyxiuZ0eAAAA:8 a=OJgbNNlONyroBnbhEqMA:9 a=QEXdDO2ut3YA:10 a=SSmOFEACAAAA:8
a=EMGi6mfMnlWLX1VXnNUA:9 a=_W_S_7VecoQA:10 a=p403mkujtbAA:10
Received: from postcard.entp.com (postcard.entp.com [23.235.226.122]) (using
TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate
requested) by smtp10.stejtech.net (Postfix) with ESMTPS id A91B97CC04B for
mathas.olausson@solidify.se; Sun, 25 Jan 2015 05:49:29 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tenderapp.com; s=sentry;
h=List-Subscribe:List-Post:List-Unsubscribe:List-Id:List-Help:List-Archive:Content-Type:Mime-Version:Subject:References:In-Reply-To:Message-Id:To:From:Date; bh=Uy+HXrPywtCrFO1eHExC588nHkVC9jmY7VeB/xGAVL4=;
b=qvxkrgn9FvmOZe0CCx7gu9qGRGWKiwCFrt4q4KP5Qg8gC7yJseJ65m2EXbgMcRXERP30NaxH4Kzuv3jQaXt0z1XUW9Z7kZaJWM3tDVIJO39sI5YhpzY5wrEWtI/SpmmB66ljxLv8oRI250om8TTii3c2J9vUIAIZ5Igv+oUxvbHXLHBQMyamLWC1rcSyXhpb7Yg/JXa+WfmRPSPHLiVNQXanviEd6lQByWKobakrxEJ3Q0H1mhSInyPwS1uJ7Rw6ac0BY0pI/i3GTabuXXugPxFmUUtDFd8Gbjk9mz1N2zYvAkxTr+a4E9GCQc6c1kwBlt63+1ObGfiRJaA/my2pGQ==;
Received: from [192.228.96.5] (helo=tenderapp.com) by postcard.entp.com with
esmtpa (Exim 4.82) (envelope-from
tender2+d541ac88ed2712d4cc68043eb7fb5472d289410d2@tenderapp.com) id
1YFF8Y-0000IT-Uj for mathas.olausson@solidify.se; Sun, 25 Jan 2015 04:49:27
+0000
Date: Sun, 25 Jan 2015 04:49:26 +0000
From: =?utf-8?Q?Dalmiro_Gra=C3=B1as?=
tender2+d541ac88ed2712d4cc68043eb7fb5472d289410d2@tenderapp.com
To: mathas.olausson@solidify.se
Message-ID: 18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_11@octopus-deploy.tenderapp
In-Reply-To: 18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_10@octopus-deploy.tenderapp
References: 18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_10@octopus-deploy.tenderapp 18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_9@octopus-deploy.tenderapp
18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_8@octopus-deploy.tenderapp 18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_7@octopus-deploy.tenderapp
18789_2694_541ac88ed2712d4cc68043eb7fb5472d289410d2_6@octopus-deploy.tenderapp
Subject: Re: Cloning a project through the REST API? [Questions #2694]
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary=“mimepart_54c475d6bde1c_e633f85956d913852077”
List-Archive: http://help.octopusdeploy.com/discussions/questions
List-Help: http://help.octopusdeploy.com
List-Id: Octopus Deploy <help.octopusdeploy.com>
X-Pm-Keepid: true
X-Tender: notification
List-Unsubscribe: http://help.octopusdeploy.com/discussions/questions/2694-cloning-a-project-through-the-rest-api
List-Post: tender2+d541ac88ed2712d4cc68043eb7fb5472d289410d2@tenderapp.com, http://help.octopusdeploy.com/discussions/questions/2694-cloning-a-project-through-the-rest-api
List-Subscribe: http://help.octopusdeploy.com/discussions/questions/2694-cloning-a-project-through-the-rest-api
X-Tender-Site: 18789
Return-Path: tender2+d541ac88ed2712d4cc68043eb7fb5472d289410d2@tenderapp.com

untitled (8 KB)

untitled (341 Bytes)

Hello Dalmiro Grañas,

This is the error I’m getting from using the snippet:

Cannot find an overload for “post” and the argument count: “2”.
At D:\octopustest.ps1:48 char:1

  • $endpoint.post("~/api/projects?clone=" + $OriginalProject.Id, $newproject)
  •   + CategoryInfo          : NotSpecified: (:) [], MethodException
      + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Hi Femi,

Are you able to export the project, and then re-import it (as suggested in http://help.octopusdeploy.com/discussions/problems/44982) and see if that fixes the issue you are seeing?

Thank you and best regards,
Henrik

I’m also getting this error after upgrading from 3.2.23 - 3.4.13:
Cannot find an overload for “post” and the argument count: “2”.

Code used is from here: https://gist.github.com/Dalmirog/ded59a51ad52b104be9b

I created a new project to clone in case it may have been corrupted but no luck.

Anyone know of a fix for this? Thanks

Hi Conrad,

If you add $null to the call to .post (e.g. $endpoint.post("~/api/projects?clone=" + $OriginalProject.Id, $newproject, $null)) it should work again for you.

I hope that helps!

Thank you and warm regards,
Henrik

Perfect, Thanks for your help Henrik.

Hi Conrad,

Great to hear!

Happy deployments!

Thank you,
Henrik