diff --git a/src/Misc/layoutroot/run-helper.cmd.template b/src/Misc/layoutroot/run-helper.cmd.template index 6b594d4f357..389280ef7c8 100644 --- a/src/Misc/layoutroot/run-helper.cmd.template +++ b/src/Misc/layoutroot/run-helper.cmd.template @@ -10,6 +10,13 @@ if %ERRORLEVEL% EQU 0 ( exit /b 0 ) +if "%ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE%"=="1" ( + if %ERRORLEVEL% EQU 7 ( + echo "Runner listener exit with deprecated version error code: %ERRORLEVEL%." + exit /b %ERRORLEVEL% + ) +) + if %ERRORLEVEL% EQU 1 ( echo "Runner listener exit with terminated error, stop the service, no retry needed." exit /b 0 diff --git a/src/Misc/layoutroot/run-helper.sh.template b/src/Misc/layoutroot/run-helper.sh.template index 9f2b3cc4457..813c747355a 100755 --- a/src/Misc/layoutroot/run-helper.sh.template +++ b/src/Misc/layoutroot/run-helper.sh.template @@ -34,11 +34,13 @@ fi updateFile="update.finished" "$DIR"/bin/Runner.Listener run $* - returnCode=$? if [[ $returnCode == 0 ]]; then echo "Runner listener exit with 0 return code, stop the service, no retry needed." exit 0 +elif [[ "$ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE" == "1" && $returnCode -eq 7 ]]; then + echo "Runner listener exit with deprecated version exit code: ${returnCode}." + exit "$returnCode" elif [[ $returnCode == 1 ]]; then echo "Runner listener exit with terminated error, stop the service, no retry needed." exit 0 diff --git a/src/Misc/layoutroot/run.cmd b/src/Misc/layoutroot/run.cmd index 692b38f9b9f..d0a4052c9bc 100644 --- a/src/Misc/layoutroot/run.cmd +++ b/src/Misc/layoutroot/run.cmd @@ -25,7 +25,14 @@ call "%~dp0run-helper.cmd" %* if %ERRORLEVEL% EQU 1 ( echo "Restarting runner..." goto :launch_helper -) else ( - echo "Exiting runner..." - exit /b 0 ) + +if "%ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE%"=="1" ( + if %ERRORLEVEL% EQU 7 ( + echo "Exiting runner with deprecated version error code: %ERRORLEVEL%" + exit /b %ERRORLEVEL% + ) +) + +echo "Exiting runner..." +exit /b 0 diff --git a/src/Misc/layoutroot/run.sh b/src/Misc/layoutroot/run.sh index 57f18ee00e1..27b3cb404b2 100755 --- a/src/Misc/layoutroot/run.sh +++ b/src/Misc/layoutroot/run.sh @@ -19,6 +19,9 @@ run() { returnCode=$? if [[ $returnCode -eq 2 ]]; then echo "Restarting runner..." + elif [[ "$ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE" == "1" && $returnCode -eq 7 ]]; then + echo "Exiting runner..." + exit "$returnCode" else echo "Exiting runner..." exit 0 @@ -42,6 +45,9 @@ runWithManualTrap() { returnCode=$? if [[ $returnCode -eq 2 ]]; then echo "Restarting runner..." + elif [[ "$ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE" == "1" && $returnCode -eq 7 ]]; then + echo "Exiting runner..." + exit "$returnCode" else echo "Exiting runner..." # Unregister signal handling before exit diff --git a/src/Runner.Common/Constants.cs b/src/Runner.Common/Constants.cs index 583958981a9..c3d56ec3c41 100644 --- a/src/Runner.Common/Constants.cs +++ b/src/Runner.Common/Constants.cs @@ -159,6 +159,7 @@ public static class ReturnCode // and the runner should be restarted. This is a temporary code and will be removed in the future after // the runner is migrated to runner admin. public const int RunnerConfigurationRefreshed = 6; + public const int RunnerVersionDeprecated = 7; } public static class Features @@ -277,6 +278,7 @@ public static class Actions public static readonly string AllowUnsupportedCommands = "ACTIONS_ALLOW_UNSECURE_COMMANDS"; public static readonly string AllowUnsupportedStopCommandTokens = "ACTIONS_ALLOW_UNSECURE_STOPCOMMAND_TOKENS"; public static readonly string RequireJobContainer = "ACTIONS_RUNNER_REQUIRE_JOB_CONTAINER"; + public static readonly string ReturnVersionDeprecatedExitCode = "ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE"; public static readonly string RunnerDebug = "ACTIONS_RUNNER_DEBUG"; public static readonly string StepDebug = "ACTIONS_STEP_DEBUG"; } diff --git a/src/Runner.Listener/Program.cs b/src/Runner.Listener/Program.cs index 80852d32c4d..d2923736402 100644 --- a/src/Runner.Listener/Program.cs +++ b/src/Runner.Listener/Program.cs @@ -141,9 +141,9 @@ private async static Task MainAsync(IHostContext context, string[] args) } catch (AccessDeniedException e) when (e.ErrorCode == 1) { - terminal.WriteError($"An error occured: {e.Message}"); + terminal.WriteError($"An error occurred: {e.Message}"); trace.Error(e); - return Constants.Runner.ReturnCode.TerminatedError; + return GetRunnerVersionDeprecatedExitCode(); } catch (RunnerNotFoundException e) { @@ -159,6 +159,16 @@ private async static Task MainAsync(IHostContext context, string[] args) } } + private static int GetRunnerVersionDeprecatedExitCode() + { + if (StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable(Constants.Variables.Actions.ReturnVersionDeprecatedExitCode))) + { + return Constants.Runner.ReturnCode.RunnerVersionDeprecated; + } + + return Constants.Runner.ReturnCode.TerminatedError; + } + private static void LoadAndSetEnv() { var binDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);