Skip to content

Commit

Permalink
(chocolateyGH-1000) Allow $LASTEXITCODE check by feature
Browse files Browse the repository at this point in the history
For folks that may need it, allow failing a package again by the last
external command exit code or `exit` from a PowerShell script. Note
that this is not recommended.

To do this, one just needs to flip on the feature
`scriptsCheckLastExitCode`.
  • Loading branch information
ferventcoder committed Oct 5, 2016
1 parent 5f62487 commit 6a81892
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public static class Environment
public static readonly string ChocolateyIgnoreChecksums = "ChocolateyIgnoreChecksums";
public static readonly string ChocolateyAllowEmptyChecksums = "ChocolateyAllowEmptyChecksums";
public static readonly string ChocolateyAllowEmptyChecksumsSecure = "ChocolateyAllowEmptyChecksumsSecure";
public static readonly string ChocolateyCheckLastExitCode = "ChocolateyCheckLastExitCode";
public static readonly string ChocolateyPowerShellHost = "ChocolateyPowerShellHost";
public static readonly string ChocolateyForce = "ChocolateyForce";
}
Expand Down Expand Up @@ -154,6 +155,7 @@ public static class Features
public static readonly string IgnoreInvalidOptionsSwitches = "ignoreInvalidOptionsSwitches";
public static readonly string UsePackageExitCodes = "usePackageExitCodes";
public static readonly string UseFipsCompliantChecksums = "useFipsCompliantChecksums";
public static readonly string ScriptsCheckLastExitCode = "scriptsCheckLastExitCode";
}

public static class Messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile
config.Features.IgnoreInvalidOptionsSwitches = set_feature_flag(ApplicationParameters.Features.IgnoreInvalidOptionsSwitches, configFileSettings, defaultEnabled: true, description: "Ignore Invalid Options/Switches - If a switch or option is passed that is not recognized, should choco fail? Available in 0.9.10+.");
config.Features.UsePackageExitCodes = set_feature_flag(ApplicationParameters.Features.UsePackageExitCodes, configFileSettings, defaultEnabled: true, description: "Use Package Exit Codes - Package scripts can provide exit codes. With this on, package exit codes will be what choco uses for exit when non-zero (this value can come from a dependency package). Chocolatey defines valid exit codes as 0, 1605, 1614, 1641, 3010. With this feature off, choco will exit with a 0 or a 1 (matching previous behavior). Available in 0.9.10+.");
config.Features.UseFipsCompliantChecksums = set_feature_flag(ApplicationParameters.Features.UseFipsCompliantChecksums, configFileSettings, defaultEnabled: false, description: "Use FIPS Compliant Checksums - Ensure checksumming done by choco uses FIPS compliant algorithms. Not recommended unless required by FIPS Mode. Enabling on an existing installation could have unintended consequences related to upgrades/uninstalls. Available in 0.9.10+.");
config.Features.ScriptsCheckLastExitCode = set_feature_flag(ApplicationParameters.Features.ScriptsCheckLastExitCode, configFileSettings, defaultEnabled: false, description: "Scripts Check $LastExitCode (external commands) - Leave this off unless you absolutely need it while you fix your package scripts to use `throw 'error message'` or `Set-PowerShellExitCode #` instead of `exit #`. This behavior started in 0.9.10 and produced hard to find bugs. If the last external process exits successfully but with an exit code of not zero, this could cause hard to detect package failures. Available in 0.10.3+. Will be removed in 0.11.0.");
config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ public sealed class FeaturesConfiguration
public bool IgnoreInvalidOptionsSwitches { get; set; }
public bool UsePackageExitCodes { get; set; }
public bool UseFipsCompliantChecksums { get; set; }
//todo remove in 0.11.0
public bool ScriptsCheckLastExitCode { get; set; }
}

//todo: retrofit other command configs this way
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static void set_environment_variables(ChocolateyConfiguration config)
if (!config.Features.ChecksumFiles) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyIgnoreChecksums, "true");
if (config.Features.AllowEmptyChecksums) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyAllowEmptyChecksums, "true");
if (config.Features.AllowEmptyChecksumsSecure) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyAllowEmptyChecksumsSecure, "true");
if (config.Features.ScriptsCheckLastExitCode) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyCheckLastExitCode, "true");
Environment.SetEnvironmentVariable("chocolateyRequestTimeout", config.WebRequestTimeoutSeconds.to_string() + "000");
Environment.SetEnvironmentVariable("chocolateyResponseTimeout", config.CommandExecutionTimeoutSeconds.to_string() + "000");

Expand Down

0 comments on commit 6a81892

Please sign in to comment.