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 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 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 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);
        }
コード例 #5
0
        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);
        }