Skip to content

Instantly share code, notes, and snippets.

@mshenoy83
Last active August 23, 2017 13:21
Show Gist options
  • Save mshenoy83/0ef03b990567cfe005112083ca2d2475 to your computer and use it in GitHub Desktop.
Save mshenoy83/0ef03b990567cfe005112083ca2d2475 to your computer and use it in GitHub Desktop.
Octopus Deploy - Multiple releases from single project in TeamCIty
using Octopus.Client;
using Octopus.Client.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OctopusDeploymentClient
{
class Program
{
/// <summary>
///
/// </summary>
/// <param name="args">
/// 0 -- octopusServerAddress
/// 1 -- apiKey
/// 2 -- Environment Name
/// 3 -- Comma seperated project list
/// 4 -- Nuget version number</param>
static void Main(string[] args)
{
var endpoint = new OctopusServerEndpoint(args[0], args[1]);
var repository = new OctopusRepository(endpoint);
var octoenv = repository.Environments.GetAll().FirstOrDefault(x => x.Name == args[2]);
var projects = args[3].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 = args[4];
release.ProjectId = octoproj.Id;
foreach(var packages in octotemplate.Packages)
{
var selectedpackage = new SelectedPackage();
selectedpackage.StepName = packages.StepName;
selectedpackage.Version = args[4];
release.SelectedPackages.Add(selectedpackage);
}
var crRelease = repository.Releases.Create(release);
var newdepl = new DeploymentResource();
newdepl.ReleaseId = crRelease.Id;
newdepl.ProjectId = octoproj.Id;
newdepl.EnvironmentId = octoenv.Id;
repository.Deployments.Create(newdepl);
}
}
}
}
@LuceroPeniarrieta
Copy link

Is working perfectly!!! Thank you

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