Created
October 30, 2014 04:13
-
-
Save DamianMac/cab420adb9f9a915b028 to your computer and use it in GitHub Desktop.
Create a release with Octopus Client API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var server = "http://yourserveraddress:8065/"; //Your server and IP address | |
var apiKey = "API-XXXXXXXXXXXXXXXXXXXXXXXXX"; // Get this from your 'profile' page in the Octopus web portal | |
var endpoint = new OctopusServerEndpoint(server, apiKey); | |
var repository = new OctopusRepository(endpoint); | |
var projectId = "projects-225"; //your project id | |
//This pulls out the info you need, the same call that's made on the Create Release page in the UI | |
var template = repository.Client.Get<Octopus.Client.Model.ReleaseTemplateResource>("/api/deploymentprocesses/deploymentprocess-" + projectId + "/template"); | |
var release = new Octopus.Client.Model.ReleaseResource(); | |
release.Version = template.NextVersionIncrement;; | |
release.ProjectId = projectId; | |
foreach (var package in template.Packages) | |
{ | |
release.SelectedPackages.Add(new Octopus.Client.Model.SelectedPackage(package.StepName, package.VersionSelectedLastRelease)); //Use a new package version if you know it | |
} | |
var result = repository.Releases.Create(release); | |
Hi, this works.
```
var endpoint = new OctopusServerEndpoint("http://localhost:8099", "API-XXXXXXXXXXXXXXXXXXXXX");
var repository = new OctopusRepository(endpoint);
var octoenv = repository.Environments.GetAll().FirstOrDefault(x => x.Name == "Dev");
var projects = "project1,prokect2,project3".Split(',');
foreach (var project in projects)
{
var octoproj = repository.Projects.Get(project);
var octoproc = repository.DeploymentProcesses.Get(octoproj.DeploymentProcessId);
var channel = repository.Client.Get<ChannelResource>("/api/projects/" + octoproj.Id + "/channels");
var octotemplate = repository.DeploymentProcesses.GetTemplate(octoproc, channel);
var release = new ReleaseResource();
release.Version = "1.0.0.15";
release.ProjectId = octoproj.Id;
foreach(var packages in octotemplate.Packages)
{
var selectedpackage = new SelectedPackage();
selectedpackage.StepName = packages.StepName;
selectedpackage.Version = "1.0.0.15";
release.SelectedPackages.Add(selectedpackage);
}
var crRelease = repository.Releases.Create(release);
var newderpl = new DeploymentResource();
newderpl.ReleaseId = crRelease.Id;
newderpl.ProjectId = octoproj.Id;
newderpl.EnvironmentId = octoenv.Id;
repository.Deployments.Create(newderpl);
//release.SelectedPackages.Add(new SelectedPackage())
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work any more post-channel introduction.