"Deploy a Windows Service Step" via Octopus.Client

Hi

I’m trying to automate the creation of projects and windows service installation via Octopus.Client.
How do I add "“Deploy a Windows Service Step” to a deployment, any hints are appreciated…
The step template is not accessible through e.g. repo.ActionTemplates.FindByName(“Deploy a Windows Service Step”)…

Thank you.

solution:

private static DeploymentStepResource SetupDeploy(string serviceName, IOctopusRepository repo)
        {
            var deploymentStep = new DeploymentStepResource
            {
                Name = "Deploy", //Change this to what you want the step to be named.
                Condition = DeploymentStepCondition.Success,
                StartTrigger = DeploymentStepStartTrigger.StartAfterPrevious
            };
            deploymentStep.Properties.Add(Property("Octopus.Action.TargetRoles", serviceName));
            //Initialize new Action
            var action = new DeploymentActionResource
            {
                Name = deploymentStep.Name,
                ActionType = "Octopus.WindowsService",
            };
            Console.WriteLine("Adding actions");
            action.Properties.Add(Property("Octopus.Action.EnabledFeatures", "Octopus.Features.WindowsService,Octopus.Features.ConfigurationTransforms,Octopus.Features.ConfigurationVariables"));
            action.Properties.Add(Property("Octopus.Action.Package.AutomaticallyRunConfigurationTransformationFiles", "True"));
            action.Properties.Add(Property("Octopus.Action.Package.AutomaticallyUpdateAppSettingsAndConnectionStrings", "True"));
            action.Properties.Add(Property("Octopus.Action.Package.DownloadOnTentacle", "False"));
            action.Properties.Add(Property("Octopus.Action.Package.FeedId", "feeds-builtin"));
            action.Properties.Add(Property("Octopus.Action.Package.PackageId", serviceName));
            action.Properties.Add(Property("Octopus.Action.WindowsService.CreateOrUpdateService", "True"));
            action.Properties.Add(Property("Octopus.Action.WindowsService.CustomAccountName", null));
            action.Properties.Add(Property("Octopus.Action.WindowsService.CustomAccountPassword", null));
            action.Properties.Add(Property("Octopus.Action.WindowsService.Description", ""));
            action.Properties.Add(Property("Octopus.Action.WindowsService.DisplayName", serviceName));
            action.Properties.Add(Property("Octopus.Action.WindowsService.ExecutablePath", $"{serviceName}.exe"));
            action.Properties.Add(Property("Octopus.Action.WindowsService.ServiceAccount", "LocalSystem"));
            action.Properties.Add(Property("Octopus.Action.WindowsService.ServiceName", serviceName));
            action.Properties.Add(Property("Octopus.Action.WindowsService.StartMode", "auto"));
            deploymentStep.Actions.Add(action);
            //Add the action to your deployment step
            Console.WriteLine("Action added");
            return deploymentStep;
        }

Hi,

Thanks for posting your solution!

Vanessa