예제 #1
0
 public void ApplyToTest(Test test)
 {
     if (ScriptingEnvironment.SafelyGetPowerShellVersion().Major < 5)
     {
         test.RunState = RunState.Skipped;
         test.Properties.Set(PropertyNames.SkipReason, "This test requires PowerShell 5 or newer.");
     }
 }
예제 #2
0
        static string GetPsDebugCommand(IVariables variables)
        {
            //https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-psdebug?view=powershell-6
            var traceArg     = variables[PowerShellVariables.PSDebug.Trace];
            var traceCommand = "-Trace 0";

            int.TryParse(traceArg, out var traceArgAsInt);
            bool.TryParse(traceArg, out var traceArgAsBool);
            if (traceArgAsInt > 0 || traceArgAsBool)
            {
                var powerShellVersion = ScriptingEnvironment.SafelyGetPowerShellVersion();

                if (powerShellVersion.Major < 5 && powerShellVersion.Major > 0)
                {
                    Log.Warn($"{PowerShellVariables.PSDebug.Trace} is enabled, but PowerShell tracing is only supported with PowerShell versions 5 and above. This server is currently running PowerShell version {powerShellVersion}.");
                }
                else
                {
                    Log.Warn($"{PowerShellVariables.PSDebug.Trace} is enabled. This should only be used for debugging, and then disabled again for normal deployments.");
                    if (traceArgAsInt > 0)
                    {
                        traceCommand = $"-Trace {traceArgAsInt}";
                    }
                    if (traceArgAsBool)
                    {
                        traceCommand = $"-Trace 2";
                    }
                }
            }

            var strictArg     = variables[PowerShellVariables.PSDebug.Strict];
            var strictCommand = "";

            if (bool.TryParse(strictArg, out var strictArgAsBool) && strictArgAsBool)
            {
                Log.Info($"{PowerShellVariables.PSDebug.Strict} is enabled, putting PowerShell into strict mode where variables must be assigned a value before being referenced in a script. If a variable is referenced before a value is assigned, an exception will be thrown. This feature is experimental.");
                strictCommand = " -Strict";
            }

            return($"Set-PSDebug {traceCommand}{strictCommand};");
        }
예제 #3
0
        public void PowerShell4DoesntSupport(string variableValue)
        {
            //this may cause an `Inconclusive: Outcome value 0 is not understood` error in Rider
            //known bug - https://youtrack.jetbrains.com/issue/RSRP-465549
            if (ScriptingEnvironment.SafelyGetPowerShellVersion().Major != 4)
            {
                Assert.Inconclusive("This test requires PowerShell 4");
            }

            using (var scriptFile = new TemporaryFile(Path.ChangeExtension(Path.GetTempFileName(), "ps1")))
            {
                File.WriteAllText(scriptFile.FilePath, "Write-Host $mysecrect");
                var calamariVariableDictionary = GetVariables();
                calamariVariableDictionary.Set("Octopus.Action.PowerShell.PSDebug.Trace", variableValue);

                var result = ExecuteScript(new PowerShellScriptExecutor(), scriptFile.FilePath, calamariVariableDictionary);

                result.AssertOutput("KingKong");
                result.AssertOutput("Octopus.Action.PowerShell.PSDebug.Trace is enabled, but PowerShell tracing is only supported with PowerShell versions 5 and above. This server is currently running PowerShell version 4.0.");
            }
        }