Create release and rule-test

When creating a release there is a post to the API for a rule-test , i.e. /api/channels/rule-test which returns if a particular step satisfied the version range and tag requirements for a rule.

I am attempting to access this logic for a specific step in a package as I create a new deployment but am missing the information for it.
I have:

// get the deployment process key from the project
var deploymentProcess = project.Links.Where(l => l.Key.Equals(“DeploymentProcess”)).First();
// get the template for the project and current channel
var template = octopus.Repository.Client.Get(deploymentProcess.Value + “/template?channel=” + channel.Id);

// now test each package in the template to ensure it meets the rules
foreach (var package in template.Packages)
{
// logic to test version range and pre release tag of each package here
}

Is there a better way to get the template information that will include the test for the packages for the channel?

Ian

Hi Ian,

Thanks for getting in touch. It looks like you’re using our Octopus.Client NuGet package to interact w/ Octopus (correct me if I’m wrong) and it’s not always obvious how to do certain things. The good news is that this NuGet package and our octo.exe command line tool are open source and you can review their source code to see how to accomplish various tasks. In this case, I didn’t know how to do this so I searched the repository found our ChannelVersionRuleTester class which shows how to do this. You can review it at the following URL.
https://github.com/OctopusDeploy/OctopusClients/blob/master/source/Octo/Commands/ChannelVersionRuleTester.cs

This is should be a pretty good starting point as to how to execute this. There are quite a few examples of how to retrieve resources and work with them in that repository.

Let me know how you go.

Thanks

Rob

Hi,
Thanks for your response.
Yes I am using the Octopus.Client package in Visual Studio to interact with Octopus. Unfortunately the documentation on this is a little sparse and the searching on GitHub is very rudimentary.

I will have a look at this and see what I can find and let you know.

Regards
Ian

Hi Rob,
Unfortunately, there does not appear to be a nuget package for Octopus.Cli that I can use to actually get library for the octo tool.
Is there another way to do this?
Ian

Hi Ian,

Thanks for the reply. You’re correct in that we don’t have a nuget package for the octo.exe command line tool. I was suggesting to look at the linked example code to mirror it in your own script/console app to accomplish your task.

In regards to our documentation, we’re aware that its current state isn’t ideal and we talked about how we’d like to improve it in our 2017 kickoff blog post.

Octopus will expose its API with Swagger, making it easier for end users to use our APIs

This should get better in the future but in the mean time, we’re here to help.

Let me know how you go.

Thanks

Rob