I’ve been attempting all day to create a function to create a release and deploy it.
However the Octopus client has almost no documentation and is little more than a cover over all of the methods. I feel that in terms of actual business logic it doesn’t provide anything over the REST API.
The alternative is the Octo executable. This is cannot be used in a programmatic way except by executing it. I want to be able to iterate over multiple projects and deploy them with certain conditions.
How come you can’t expose the methods which the Octo.exe lets you perform in a NuGet package.
I’ve got this far - total prototyping code, but hit one more exception due to using a variable for the package ID, and I’ve had enough.
var project = this.octopus.Projects.FindByName(manifestProject.Name);
if (string.IsNullOrEmpty(project.VersioningStrategy.DonorPackageStepId))
{
return;
}
var channel = this.octopus.Channels.FindByName(project, channelName);
var process = this.octopus.DeploymentProcesses.Get(project.DeploymentProcessId);
var release = new ReleaseResource
{
ProjectId = project.Id,
ChannelId = channel.Id,
SelectedPackages = new List<SelectedPackage>()
};
foreach (var step in process.Steps)
{
var packageStep = step.Actions.SingleOrDefault(x => x.ActionType == "Octopus.TentaclePackage");
if (packageStep == null)
{
continue;
}
var rule = channel.Rules.SingleOrDefault(x => x.Actions.Contains(step.Name));
var packageId = packageStep.Properties["Octopus.Action.Package.PackageId"].Value;
var packages = this.octopus.BuiltInPackageRepository.ListPackages(packageId, 0, int.MaxValue);
var package = rule != null ? packages.Items.First(x => Regex.IsMatch(x.Version.Split(new[] { '-' }, 1).Last(), rule.Tag)) : packages.Items.First();
release.SelectedPackages.Add(new SelectedPackage(step.Name, package.Version));
if (step.Actions.Any(a => a.Id == project.VersioningStrategy.DonorPackageStepId))
{
release.Version = package.Version;
}
}
This would greatly simplify the process.
Thanks