Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a release with Octopus Client API
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);
@davejhahn

This comment has been minimized.

Copy link

@davejhahn davejhahn commented Jan 22, 2016

This doesn't work any more post-channel introduction.

@mshenoy83

This comment has been minimized.

Copy link

@mshenoy83 mshenoy83 commented Jul 4, 2016

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())
        }
@mshenoy83

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.