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)); }
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 Log(TextWriter stdout, TextWriter stderr, LogOptions logOptions, ILogMessageFormatter logMessageFormatter) { Stdout = stdout; Stderr = stderr; LogOptions = logOptions; LogMessageFormatter = logMessageFormatter; TaskLog = new TaskLog(stdout, stderr, logOptions); }
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)); }
public Endpoint BuildEndpoint(IDictionary <string, string> messageProperties, VariableDictionary variables, Func <string, string> accountIdResolver, Func <string, string> certificateIdResolver, Func <string, string> workerPoolIdResolver, Func <string, AccountType> accountTypeResolver, Func <string, string> feedIdResolver, ITaskLog taskLog) { var endpoint = new AzureWebAppEndpoint { AccountId = GetAccountId(messageProperties, variables, accountIdResolver, taskLog), }; messageProperties.TryGetValue(AzureWebAppServiceMessageNames.WebAppNameAttribute, out var wepAppName); messageProperties.TryGetValue(AzureWebAppServiceMessageNames.ResourceGroupNameAttribute, out var resourceGroupName); if (wepAppName is null) { throw new ControlledActionFailedException("App Service name was not provided"); } if (resourceGroupName is null) { throw new ControlledActionFailedException("Resource group name was not provided"); } endpoint.WebAppName = wepAppName; endpoint.ResourceGroupName = resourceGroupName; if (messageProperties.TryGetValue(AzureWebAppServiceMessageNames.WebAppSlotNameAttribute, out var webAppSlotName) && !string.IsNullOrWhiteSpace(webAppSlotName)) { endpoint.WebAppSlotName = webAppSlotName; } endpoint.DefaultWorkerPoolId = GetWorkerPoolId(messageProperties, variables, workerPoolIdResolver); return(endpoint); }
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)); }
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()); }
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); }
string GetAccountId(IDictionary <string, string> messageProperties, VariableDictionary variables, Func <string, string> accountIdResolver, ITaskLog taskLog) { messageProperties.TryGetValue(AzureWebAppServiceMessageNames.AccountIdOrNameAttribute, out var accountIdOrName); if (!string.IsNullOrWhiteSpace(accountIdOrName)) { var resolvedAccountId = accountIdResolver(accountIdOrName); if (!string.IsNullOrWhiteSpace(resolvedAccountId)) { return(resolvedAccountId); } } accountIdOrName = variables.Get(SpecialVariables.Action.Azure.AccountId); if (!string.IsNullOrWhiteSpace(accountIdOrName)) { var resolvedAccountId = accountIdResolver(accountIdOrName); if (!string.IsNullOrWhiteSpace(resolvedAccountId)) { return(resolvedAccountId); } } var message = $"Account with Id / Name, {accountIdOrName}, not found."; taskLog.Error(message); throw new Exception(message); }
public IActionHandlerResult Execute(IActionHandlerContext context, ITaskLog taskLog) { return(context.CalamariCommand(CalamariAzureAppService, "target-discovery") .Execute(taskLog)); }
public async Task PublishToJira(string eventType, DeploymentResource deployment, IJiraApiDeployment jiraApiDeployment, ITaskLog taskLog, CancellationToken cancellationToken) { if (JiraIntegrationUnavailable(deployment)) { jiraApiDeployment.HandleJiraIntegrationIsUnavailable(); return; } var serverUri = serverConfigurationStore.GetServerUri()?.TrimEnd('/'); if (string.IsNullOrWhiteSpace(serverUri)) { taskLog.Warn("To use Jira integration you must have the Octopus server's external url configured (see the Configuration/Nodes page)"); return; } if (string.IsNullOrWhiteSpace(store.GetConnectAppUrl()) || string.IsNullOrWhiteSpace(store.GetConnectAppPassword()?.Value)) { taskLog.Warn("Jira integration is enabled but settings are incomplete, ignoring deployment events"); return; } var taskLogBlock = taskLogFactory.CreateBlock(taskLog, $"Sending Jira state update - {eventType}"); // get token from connect App var token = await connectAppClient.GetAuthTokenFromConnectApp(taskLogBlock); if (token is null) { taskLogFactory.Finish(taskLogBlock); return; } var getDeploymentEnvironmentResponse = await mediator.Request(new GetDeploymentEnvironmentRequest(deployment.EnvironmentId), cancellationToken); var deploymentEnvironment = getDeploymentEnvironmentResponse.DeploymentEnvironment; var environmentSettings = deploymentEnvironmentSettingsProvider .GetSettings <DeploymentEnvironmentSettingsMetadataProvider.JiraDeploymentEnvironmentSettings?>( JiraConfigurationStore.SingletonId, deployment.EnvironmentId.Value) ?? new DeploymentEnvironmentSettingsMetadataProvider.JiraDeploymentEnvironmentSettings(); var data = await PrepareOctopusJiraPayload( eventType, serverUri, deployment, jiraApiDeployment, cancellationToken, deploymentEnvironment, environmentSettings); // Push data to Jira await SendToJira( token, data, deployment, taskLogBlock, deploymentEnvironment, environmentSettings); taskLogFactory.Finish(taskLogBlock); }
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)); }