public IActionHandlerResult Execute(IActionHandlerContext context, ITaskLog taskLog)
        {
            var syntax = context.Variables.GetEnum(KnownVariables.Action.Script.Syntax, ScriptSyntax.PowerShell);

            var useBundledTooling = context.Variables.GetFlag(KnownVariables.Action.UseBundledTooling, true);

            if (useBundledTooling)
            {
                // Warn that the use of bundled tooling is not recommended
                taskLog.Warn($"Using the Azure tools bundled with Octopus Deploy is not recommended. Learn more about Azure Tools at https://g.octopushq.com/AzureTools.");
            }

            var builder = context.CalamariCommand(AzureConstants.CalamariAzure, "run-script")
                          .WithAzureCLI(context, taskLog);

            if (syntax == ScriptSyntax.PowerShell)
            {
                builder = builder.WithAzureCmdlets(context, taskLog);
            }

            var isInPackage = KnownVariableValues.Action.Script.ScriptSource.Package.Equals(context.Variables.Get(KnownVariables.Action.Script.ScriptSource), StringComparison.OrdinalIgnoreCase);

            if (isInPackage)
            {
                builder.WithStagedPackageArgument();
            }

            return(builder.Execute(taskLog));
        }
Esempio n. 2
0
        public IActionHandlerResult Execute(IActionHandlerContext context, ITaskLog taskLog)
        {
            var builder = context.CalamariCommand(CalamariTerraform, ToolCommand);

            if (context.DeploymentTargetType.SelectValueOr(targetType => targetType != DeploymentTargetType.Ssh, true))
            {
                builder.WithTool(TerraformTools.TerraformCli);
            }

            var isInPackage = KnownVariableValues.Action.Script.ScriptSource.Package.Equals(context.Variables.Get(KnownVariables.Action.Script.ScriptSource), StringComparison.OrdinalIgnoreCase);

            if (isInPackage)
            {
                builder.WithStagedPackageArgument();
            }
            else
            {
                var template = context.Variables.Get(TerraformSpecialVariables.Action.Terraform.Template);
                var templateParametersRaw   = context.Variables.GetRaw(TerraformSpecialVariables.Action.Terraform.TemplateParameters);
                var userDefinedEnvVariables = GetEnvironmentVariableArgs(context.Variables);

                if (string.IsNullOrEmpty(template))
                {
                    throw new KnownDeploymentFailureException("No template supplied");
                }

                if (string.IsNullOrEmpty(templateParametersRaw))
                {
                    if (!AnyEnvironmentVariablesContainTerraformVars(userDefinedEnvVariables))
                    {
                        throw new KnownDeploymentFailureException("No template parameters applied");
                    }

                    templateParametersRaw = "{}";
                }

                var templateHandler = cloudTemplateHandlerFactory.GetHandler(TerraformConstants.CloudTemplateProviderId, template);

                if (templateHandler == null)
                {
                    throw new KnownDeploymentFailureException("Could not parse Terraform template as JSON or HCL");
                }

                var templateFormat     = templateHandler is TerraformJsonCloudTemplateHandler ? TerraformTemplateFormat.Json : TerraformTemplateFormat.Hcl;
                var metadata           = templateHandler.ParseTypes(template);
                var templateParameters = TerraformVariableFileGenerator.ConvertStringPropsToObjects(templateFormat, context.Variables, templateParametersRaw, metadata);

                builder.WithDataFileNoBom(
                    template,
                    templateFormat == TerraformTemplateFormat.Json ? TerraformSpecialVariables.JsonTemplateFile : TerraformSpecialVariables.HclTemplateFile
                    )
                .WithDataFileNoBom(
                    templateParameters,
                    templateFormat == TerraformTemplateFormat.Json ? TerraformSpecialVariables.JsonVariablesFile : TerraformSpecialVariables.HclVariablesFile
                    );
            }

            return(builder.Execute(taskLog));
        }
        public static ICalamariCommandBuilder WithAzureTools(
            this ICalamariCommandBuilder builder,
            IActionHandlerContext context,
            ITaskLog taskLog)
        {
            var useBundledTooling = context.Variables.GetFlag(KnownVariables.Action.UseBundledTooling, true);

            if (useBundledTooling)
            {
                taskLog.Warn($"Using the Azure tools bundled with Octopus Deploy is not recommended. Learn more about Azure Tools at https://g.octopushq.com/AzureTools.");
            }

            return(builder.WithAzureCmdlets(context, taskLog).WithAzureCLI(context, taskLog));
        }
Esempio n. 4
0
        public IActionHandlerResult Execute(IActionHandlerContext context, ITaskLog taskLog)
        {
            if (context.DeploymentTargetType.Some())
            {
                if (context.DeploymentTargetType.Value.Id != AzureWebAppDeploymentTargetTypeId)
                {
                    throw new ControlledActionFailedException(
                              $"The machine {context.DeploymentTargetName.SomeOr("<unknown>")} will not be deployed to because it is not an Azure Web Application deployment target");
                }
            }

            var commandBuilder = context.CalamariCommand(AzureConstants.CalamariAzure, "deploy-azure-app-service")
                                 .WithAzureTools(context, taskLog);

            // If we are deploying a container image, then there won't be a staged package
            if (!context.Variables.Get(SpecialVariables.Action.Azure.DeploymentType, "").Equals("Container"))
            {
                commandBuilder = commandBuilder.WithStagedPackageArgument();
            }

            return(commandBuilder.Execute(taskLog));
        }
Esempio n. 5
0
        public IActionHandlerResult Execute(IActionHandlerContext context, ITaskLog taskLog)
        {
            var deploymentId = context.Variables.Get(KnownVariables.Deployment.Id, "");
            var deployment   = mediator.Request(new GetDeploymentRequest(deploymentId.ToDeploymentId()), CancellationToken.None).GetAwaiter().GetResult().Deployment;

            var jiraServiceDeskChangeRequestId = context.Variables.Get("Octopus.Action.JiraIntegration.ServiceDesk.ServiceId");

            if (string.IsNullOrWhiteSpace(jiraServiceDeskChangeRequestId))
            {
                throw new ControlledActionFailedException("ServiceId is not set");
            }

            try
            {
                jiraDeployment.PublishToJira("in_progress", deployment, new JiraServiceDeskApiDeployment(jiraServiceDeskChangeRequestId), taskLog, CancellationToken.None).GetAwaiter().GetResult();
            }
            catch (JiraDeploymentException exception)
            {
                throw new ControlledActionFailedException(exception.Message);
            }

            return(ActionHandlerResult.FromSuccess());
        }
Esempio n. 6
0
        public IActionHandlerResult Execute(IActionHandlerContext context, ITaskLog taskLog)
        {
            var templateInPackage  = context.Variables.Get(SpecialVariables.Action.AzureResourceGroup.TemplateSource, String.Empty) == "Package";
            var template           = context.Variables.Get(SpecialVariables.Action.AzureResourceGroup.ResourceGroupTemplate) !;
            var templateParameters = GetTemplateParameters();

            var builder = context.CalamariCommand(AzureConstants.CalamariAzure, "deploy-azure-resource-group")
                          .WithAzureTools(context, taskLog);

            if (templateInPackage)
            {
                builder.WithStagedPackageArgument();
            }
            else
            {
                builder
                .WithDataFile(template, "template.json")
                .WithDataFile(templateParameters, "parameters.json");
            }

            return(builder.Execute(taskLog));

            string GetTemplateParameters()
            {
                if (templateInPackage)
                {
                    return(context.Variables.Get(SpecialVariables.Action.AzureResourceGroup.ResourceGroupTemplateParameters) !);
                }

                var parametersJson = context.Variables.GetRaw(SpecialVariables.Action.AzureResourceGroup.ResourceGroupTemplateParameters) !;

                var parameterMetadata = AzureResourceGroupActionUtils.ExtractParameterTypes(template);

                return(AzureResourceGroupActionUtils.TemplateParameters(parametersJson, parameterMetadata, context.Variables));
            }
        }
        public static ICalamariCommandBuilder WithAzureCLI(
            this ICalamariCommandBuilder builder,
            IActionHandlerContext context,
            ITaskLog taskLog)
        {
            // This is the new value that the user can set on the step. It and the legacy variable both default to true, if either are false then
            // we don't include the tooling.
            var useBundledTooling = context.Variables.GetFlag(KnownVariables.Action.UseBundledTooling, true);

            var legacyCliBundling = context.Variables.GetFlag(SpecialVariables.Action.Azure.UseBundledAzureCLI, true);

            if (legacyCliBundling == false)
            {
                // user has explicitly used the legacy flag to switch off bundling, tell them it's available on the step now
                taskLog.Warn($"The {SpecialVariables.Action.Azure.UseBundledAzureCLI} variable has been used to disable using the bundled Azure CLI. Note that this variable is deprecated and will be removed in a future version, please use the bundling options on the step to control this behavior now.");
            }

            if (useBundledTooling && legacyCliBundling)
            {
                builder = builder.WithTool(AzureTools.AzureCLI);
            }

            return(builder);
        }
Esempio n. 8
0
 public IActionHandlerResult Execute(IActionHandlerContext context, ITaskLog taskLog)
 {
     return(context.CalamariCommand(CalamariAzureAppService, "target-discovery")
            .Execute(taskLog));
 }
 public IActionHandlerResult Execute(IActionHandlerContext context)
 {
     return(context.CalamariCommand(new CalamariFlavour("Calamari.Demo"), "my-command-name")
            .Execute());
 }
        public static ICalamariCommandBuilder WithCheckAccountIsNotManagementCertificate(this ICalamariCommandBuilder builder, IActionHandlerContext context, ITaskLog taskLog)
        {
            if (context.Variables.Get(SpecialVariables.AccountType) != AccountTypes.AzureServicePrincipalAccountType.ToString())
            {
                taskLog.Warn("Azure have announced they will be retiring Service Management API support on June 30th 2018. Please switch to using Service Principals for your Octopus Azure accounts https://g.octopushq.com/AzureServicePrincipalAccount");
            }

            return(builder);
        }
 public IActionHandlerResult Execute(IActionHandlerContext context, ITaskLog taskLog)
 {
     return(context.CalamariCommand(CalamariAzureAppService, "health-check")
            .WithCheckAccountIsNotManagementCertificate(context, taskLog)
            .Execute(taskLog));
 }