Creating deployment action via .net client does not include referenced packages

(Anm) #1

I’m trying to automate creation of projects in Octopus Deploy, using the .NET client. When trying to create a deployment action, based on one of our templates, the referenced packages are not copied when the action is created. I have not been able to find a way to work-around this.

The deployment process is for deploying to AKS using Helm. The referenced packages are for the helm chart and the application.

It appears that the only solution we have at the moment is to manually create the deployment process, effectively killing our entire efforts to automate this.

It appears this is an already known bug (https://github.com/OctopusDeploy/Issues/issues/5649). There is no follow up information however, and the bug is marked as “tiny”, which doesn’t give me hope that it will ever be addressed.

I posted to the slack (advice) channel, but so far there is no reply.

Is there a workaround to this bug? Or is there another way we can automate the creation of projects in Octopus Deploy? Or is it possible to just fix this “tiny” bug?

(Tom Peters) #5

Hi,

Thanks for getting in touch, and I’m sorry that this caused some friction for you.

Just to give you a bit more context: Actions in the deployment process currently needs to contain copies of the properties and packages that are defined in the action templates on which they are based. This is an unfortunate part of our design that we want to rectify soon. Ideally these properties and packages would not need to be duplicated in the deployment process at all, and this is a change that we want to make.

This is the reason we have not yet addressed the PR you linked to. There are some interesting edge cases involved in fixing this behavior correctly and this introduces a bit of risk. As I look at it, I’m not sure the “tiny” label is accurate :slight_smile:

As a workaround in the meantime, you can copy the appropriate properties and packages from the action template within your script against the API. Here is a sample function that uses our Octopus C# Client that will augment an action with the properties and packages from an action template.

async Task CopyPropertiesAndPackagesFromActionTemplate(IOctopusSpaceAsyncRepository repo, DeploymentActionResource action)
{
	var actionTemplateId = action.Properties["Octopus.Action.Template.Id"].Value;
	var actionTemplate = await repo.ActionTemplates.Get(actionTemplateId);
	
	// Don't copy sensitive values, because they don't roundtrip through the API
	foreach(var property in actionTemplate.Properties.Where(p => !p.Value.IsSensitive)) {
		action.Properties.Add(property.Key, property.Value);
	}
	
	foreach(var package in actionTemplate.Packages) {
		action.Packages.Add(package);
	}
}

Hope that helps, let me know if you have any other questions.

Regards,
Tom

(Anm) #6

Hi Tom/Octopus Support,

Thanks for your help. Our problem is fixed now. I honestly thought I had already tried your suggestion of copying packages, but there was obviously something that didn’t work with
what I had tried.

Best regards,

Andrew Morshead

Senior Software Developer, Platform and Infrastructure

Planday A/S