Beispiel #1
0
        public int Execute(string[] args)
        {
            var pathToPrimaryPackage = variables.GetPathToPrimaryPackage(fileSystem, false);

            var isEnableNoMatchWarningSet = variables.IsSet(PackageVariables.EnableNoMatchWarning);

            if (!isEnableNoMatchWarningSet && !string.IsNullOrEmpty(GetAdditionalFileSubstitutions()))
            {
                variables.Add(PackageVariables.EnableNoMatchWarning, "true");
            }

            var runningDeployment = new RunningDeployment(pathToPrimaryPackage, variables);

            if (pathToPrimaryPackage != null)
            {
                extractPackage.ExtractToStagingDirectory(pathToPrimaryPackage);
            }

            var filesToSubstitute = GetFilesToSubstitute();

            substituteInFiles.Substitute(runningDeployment, filesToSubstitute);

            InstallAsync(runningDeployment).GetAwaiter().GetResult();

            return(0);
        }
        string[] GetFilesToSubstitute(IVariables variables)
        {
            var isEnableNoMatchWarningSet   = variables.IsSet(PackageVariables.EnableNoMatchWarning);
            var additionalFileSubstitutions = GetAdditionalFileSubstitutions(variables);

            if (!isEnableNoMatchWarningSet)
            {
                var hasAdditionalSubstitutions = !string.IsNullOrEmpty(additionalFileSubstitutions);
                variables.AddFlag(PackageVariables.EnableNoMatchWarning, hasAdditionalSubstitutions);
            }

            var result = new List <string>();

            var runAutomaticFileSubstitution = variables.GetFlag(TerraformSpecialVariables.Action.Terraform.RunAutomaticFileSubstitution, true);

            if (runAutomaticFileSubstitution)
            {
                result.AddRange(new[] { "**/*.tf", "**/*.tf.json", "**/*.tfvars", "**/*.tfvars.json" });
            }

            var additionalFileSubstitution = additionalFileSubstitutions;

            if (!string.IsNullOrWhiteSpace(additionalFileSubstitution))
            {
                result.AddRange(additionalFileSubstitution.Split(new[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries));
            }

            return(result.ToArray());
        }
        ITopLevelExpression TryReplaceValue(ITopLevelExpression expr, IVariables variables)
        {
            switch (expr)
            {
            case KeyValuePairExpression pair:
                var logicalName = pair.Key?.Text?.LogicalValue ?? "";
                if (!IsOctopusVariableName(logicalName) && variables.IsSet(logicalName))
                {
                    log.Verbose(StructuredConfigMessages.StructureFound(logicalName));

                    var logicalValue = variables.Get(logicalName);
                    var encodedValue = Encode.Value(logicalValue);
                    var newValueExpr = new ValueExpression(new StringValue(logicalValue, encodedValue));

                    // In cases where a key was specified with neither separator nor value
                    // we have to add a separator, otherwise the value becomes part of the key.
                    var separator = pair.Separator ?? new SeparatorExpression(":");
                    return(new KeyValuePairExpression(pair.Key, separator, newValueExpr));
                }
                else
                {
                    return(expr);
                }

            default:
                return(expr);
            }
        }
Beispiel #4
0
 private void ValidateRequiredVariables()
 {
     if (!variables.IsSet(SpecialVariables.ClusterUrl))
     {
         throw new CommandException($"The variable `{SpecialVariables.ClusterUrl}` is not provided.");
     }
 }
Beispiel #5
0
        public CommandResult Execute(Script script,
                                     IVariables variables,
                                     ICommandLineRunner commandLineRunner,
                                     Dictionary <string, string>?environmentVars = null)
        {
            var environmentVariablesIncludingProxy = environmentVars ?? new Dictionary <string, string>();

            foreach (var proxyVariable in ProxyEnvironmentVariablesGenerator.GenerateProxyEnvironmentVariables())
            {
                environmentVariablesIncludingProxy[proxyVariable.Key] = proxyVariable.Value;
            }

            var prepared = PrepareExecution(script, variables, environmentVariablesIncludingProxy);

            CommandResult?result = null;

            foreach (var execution in prepared)
            {
                if (variables.IsSet(CopyWorkingDirectoryVariable))
                {
                    CopyWorkingDirectory(variables,
                                         execution.CommandLineInvocation.WorkingDirectory,
                                         execution.CommandLineInvocation.Arguments);
                }

                try
                {
                    if (execution.CommandLineInvocation.Isolate)
                    {
                        using (SemaphoreFactory.Get()
                               .Acquire("CalamariSynchronizeProcess",
                                        "Waiting for other process to finish executing script"))
                        {
                            result = commandLineRunner.Execute(execution.CommandLineInvocation);
                        }
                    }
                    else
                    {
                        result = commandLineRunner.Execute(execution.CommandLineInvocation);
                    }

                    if (result.ExitCode != 0)
                    {
                        return(result);
                    }
                }
                finally
                {
                    foreach (var temporaryFile in execution.TemporaryFiles)
                    {
                        var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();
                        fileSystem.DeleteFile(temporaryFile, FailureOptions.IgnoreFailure);
                    }
                }
            }

            return(result !);
        }
 void WarnIfHttpTimeoutHasBeenSet()
 {
     if (variables.IsSet(KnownVariables.NugetHttpTimeout))
     {
         Log.Warn(
             $"A Nuget HTTP timeout was set via the '{KnownVariables.NugetHttpTimeout}' variable. "
             + "This variable is only supported when running on .NET Framework."
             );
     }
 }