Skip to content

Instantly share code, notes, and snippets.

@Dalmirog-zz
Created January 25, 2015 04:41
Show Gist options
  • Save Dalmirog-zz/ded59a51ad52b104be9b to your computer and use it in GitHub Desktop.
Save Dalmirog-zz/ded59a51ad52b104be9b to your computer and use it in GitHub Desktop.
Clone Octopus Project
Add-Type -Path "C:\Tools\Newtonsoft.Json.dll"
Add-Type -Path "C:\Tools\Octopus.Client.dll" #Make sure its version 2.6.x or higher. Otherwhise you'll get errors with the LifecycleId property
Add-Type -Path "C:\Tools\Octopus.Platform.dll"
$OctopusURI = "" #i.e "Http://Octopus.MyAwesomeCompany.com"
$apikey = "" #i.e "API-7CH6XN0HHOU7DDEEUGKUFUR1K"
$endpoint = new-object -TypeName Octopus.Client.OctopusClient(New-Object Octopus.Client.OctopusServerEndpoint($OctopusURI,$apikey))
$repository = new-object Octopus.Client.OctopusRepository $endpoint
$newproject = New-Object Octopus.Client.Model.ProjectResource
$OriginalProject = $repository.Projects.FindByName("MyOriginalProject");
$properties = [ordered]@{
Name = "MyClonedProject"
Description = "Project cloned from $($OriginalProject.name)"
ProjectGroupId = $OriginalProject.ProjectGroupId
LifecycleId = $OriginalProject.LifecycleId
}
$newproject = New-Object Octopus.Client.Model.ProjectResource -Property $properties
$endpoint.post("~/api/projects?clone=" + $OriginalProject.Id, $newproject)
@hnrkndrssn
Copy link

hnrkndrssn commented Oct 26, 2016

FYI

If you run the above script and get the following error: Cannot find an overload for "post" and the argument count: "2"., you can add $null to the call to .post (e.g. $endpoint.post("~/api/projects?clone=" + $OriginalProject.Id, $newproject, $null))

@tudorift
Copy link

tudorift commented Jan 7, 2019

According to octopus : "Octopus.Platform.dll was removed as part of 3.0 and all that functionality has been moved into its own package."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment