From 2fb6f1175ad22edd2acbda69c07bb5af04cdadfb Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Fri, 6 Mar 2026 15:18:15 +0100 Subject: [PATCH 1/6] Exit with specified exit code when runner is outdated --- src/Misc/layoutroot/run-helper.cmd.template | 32 ++++++++++++++++----- src/Misc/layoutroot/run-helper.sh.template | 6 ++-- src/Misc/layoutroot/run.cmd | 26 ++++++++++++++--- src/Misc/layoutroot/run.sh | 6 ++++ src/Runner.Common/Constants.cs | 1 + src/Runner.Listener/Program.cs | 14 ++++++++- 6 files changed, 71 insertions(+), 14 deletions(-) diff --git a/src/Misc/layoutroot/run-helper.cmd.template b/src/Misc/layoutroot/run-helper.cmd.template index 6b594d4f357..160d9ab327c 100644 --- a/src/Misc/layoutroot/run-helper.cmd.template +++ b/src/Misc/layoutroot/run-helper.cmd.template @@ -1,27 +1,45 @@ @echo off SET UPDATEFILE=update.finished "%~dp0\bin\Runner.Listener.exe" run %* +SET RETURNCODE=%ERRORLEVEL% +SET OUTDATED_EXIT_CODE_NUM= + +if not "%ACTIONS_RUNNER_OUTDATED_EXIT_CODE%"=="" ( + set /a OUTDATED_EXIT_CODE_NUM=%ACTIONS_RUNNER_OUTDATED_EXIT_CODE% >NUL 2>NUL + if errorlevel 1 SET OUTDATED_EXIT_CODE_NUM= +) + +if not "%OUTDATED_EXIT_CODE_NUM%"=="" ( + if %OUTDATED_EXIT_CODE_NUM% LEQ 5 SET OUTDATED_EXIT_CODE_NUM= +) rem using `if %ERRORLEVEL% EQU N` instead of `if ERRORLEVEL N` rem `if ERRORLEVEL N` means: error level is N or MORE -if %ERRORLEVEL% EQU 0 ( +if %RETURNCODE% EQU 0 ( echo "Runner listener exit with 0 return code, stop the service, no retry needed." exit /b 0 ) -if %ERRORLEVEL% EQU 1 ( +if not "%OUTDATED_EXIT_CODE_NUM%"=="" ( + if "%RETURNCODE%"=="%OUTDATED_EXIT_CODE_NUM%" ( + echo "Runner listener exit with outdated error code: %RETURNCODE%." + exit /b %RETURNCODE% + ) +) + +if %RETURNCODE% EQU 1 ( echo "Runner listener exit with terminated error, stop the service, no retry needed." exit /b 0 ) -if %ERRORLEVEL% EQU 2 ( +if %RETURNCODE% EQU 2 ( echo "Runner listener exit with retryable error, re-launch runner in 5 seconds." ping 127.0.0.1 -n 6 -w 1000 >NUL exit /b 1 ) -if %ERRORLEVEL% EQU 3 ( +if %RETURNCODE% EQU 3 ( rem Wait for 30 seconds or for flag file to exists for the ephemeral runner update process finish echo "Runner listener exit because of updating, re-launch runner after successful update" FOR /L %%G IN (1,1,30) DO ( @@ -35,7 +53,7 @@ if %ERRORLEVEL% EQU 3 ( exit /b 1 ) -if %ERRORLEVEL% EQU 4 ( +if %RETURNCODE% EQU 4 ( rem Wait for 30 seconds or for flag file to exists for the runner update process finish echo "Runner listener exit because of updating, re-launch runner after successful update" FOR /L %%G IN (1,1,30) DO ( @@ -49,10 +67,10 @@ if %ERRORLEVEL% EQU 4 ( exit /b 1 ) -if %ERRORLEVEL% EQU 5 ( +if %RETURNCODE% EQU 5 ( echo "Runner listener exit with Session Conflict error, stop the service, no retry needed." exit /b 0 ) -echo "Exiting after unknown error code: %ERRORLEVEL%" +echo "Exiting after unknown error code: %RETURNCODE%" exit /b 0 \ No newline at end of file diff --git a/src/Misc/layoutroot/run-helper.sh.template b/src/Misc/layoutroot/run-helper.sh.template index 9f2b3cc4457..6b9ee5baa5a 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_OUTDATED_EXIT_CODE" =~ ^[0-9]+$ && "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" -gt 5 && "$returnCode" -eq "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" ]]; then + echo "Runner listener exit with outdated error code: ${returnCode}." + exit "$returnCode" elif [[ $returnCode == 1 ]]; then echo "Runner listener exit with terminated error, stop the service, no retry needed." exit 0 @@ -74,6 +76,6 @@ elif [[ $returnCode == 5 ]]; then echo "Runner listener exit with Session Conflict error, stop the service, no retry needed." exit 0 else - echo "Exiting with unknown error code: ${returnCode}" + echo "NOO Exiting with unknown error code: ${returnCode}" exit 0 fi diff --git a/src/Misc/layoutroot/run.cmd b/src/Misc/layoutroot/run.cmd index 692b38f9b9f..5be83b7dc9e 100644 --- a/src/Misc/layoutroot/run.cmd +++ b/src/Misc/layoutroot/run.cmd @@ -21,11 +21,29 @@ rem **************************************************************************** :launch_helper copy "%~dp0run-helper.cmd.template" "%~dp0run-helper.cmd" /Y call "%~dp0run-helper.cmd" %* +set RETURNCODE=%ERRORLEVEL% +set OUTDATED_EXIT_CODE_NUM= + +if not "%ACTIONS_RUNNER_OUTDATED_EXIT_CODE%"=="" ( + set /a OUTDATED_EXIT_CODE_NUM=%ACTIONS_RUNNER_OUTDATED_EXIT_CODE% >NUL 2>NUL + if errorlevel 1 set OUTDATED_EXIT_CODE_NUM= +) + +if not "%OUTDATED_EXIT_CODE_NUM%"=="" ( + if %OUTDATED_EXIT_CODE_NUM% LEQ 5 set OUTDATED_EXIT_CODE_NUM= +) -if %ERRORLEVEL% EQU 1 ( +if %RETURNCODE% EQU 1 ( echo "Restarting runner..." goto :launch_helper -) else ( - echo "Exiting runner..." - exit /b 0 ) + +if not "%OUTDATED_EXIT_CODE_NUM%"=="" ( + if "%RETURNCODE%"=="%OUTDATED_EXIT_CODE_NUM%" ( + echo "Exiting runner with outdated error code: %RETURNCODE%" + exit /b %RETURNCODE% + ) +) + +echo "Exiting runner..." +exit /b 0 diff --git a/src/Misc/layoutroot/run.sh b/src/Misc/layoutroot/run.sh index 57f18ee00e1..8c5c68a3e15 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 [[ -n "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" && "$returnCode" == "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" ]]; 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 [[ -n "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" && "$returnCode" == "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" ]]; 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..347d36335c3 100644 --- a/src/Runner.Common/Constants.cs +++ b/src/Runner.Common/Constants.cs @@ -278,6 +278,7 @@ public static class Actions public static readonly string AllowUnsupportedStopCommandTokens = "ACTIONS_ALLOW_UNSECURE_STOPCOMMAND_TOKENS"; public static readonly string RequireJobContainer = "ACTIONS_RUNNER_REQUIRE_JOB_CONTAINER"; public static readonly string RunnerDebug = "ACTIONS_RUNNER_DEBUG"; + public static readonly string RunnerOutdatedExitCode = "ACTIONS_RUNNER_OUTDATED_EXIT_CODE"; public static readonly string StepDebug = "ACTIONS_STEP_DEBUG"; } diff --git a/src/Runner.Listener/Program.cs b/src/Runner.Listener/Program.cs index 80852d32c4d..00d51652509 100644 --- a/src/Runner.Listener/Program.cs +++ b/src/Runner.Listener/Program.cs @@ -143,7 +143,7 @@ private async static Task MainAsync(IHostContext context, string[] args) { terminal.WriteError($"An error occured: {e.Message}"); trace.Error(e); - return Constants.Runner.ReturnCode.TerminatedError; + return GetRunnerOutdatedExitCode(); } catch (RunnerNotFoundException e) { @@ -159,6 +159,18 @@ private async static Task MainAsync(IHostContext context, string[] args) } } + private static int GetRunnerOutdatedExitCode() + { + var configuredExitCode = Environment.GetEnvironmentVariable(Constants.Variables.Actions.RunnerOutdatedExitCode); + if (int.TryParse(configuredExitCode, NumberStyles.Integer, CultureInfo.InvariantCulture, out int exitCode) && + exitCode > 5) + { + return exitCode; + } + + return Constants.Runner.ReturnCode.TerminatedError; + } + private static void LoadAndSetEnv() { var binDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); From 6525302f200b2a100ab6f09ec297e1f3259afdd3 Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Mon, 9 Mar 2026 15:26:12 +0100 Subject: [PATCH 2/6] Move deprecated version to 7 --- src/Misc/layoutroot/run-helper.cmd.template | 16 +++------------- src/Misc/layoutroot/run-helper.sh.template | 4 ++-- src/Misc/layoutroot/run.cmd | 16 +++------------- src/Misc/layoutroot/run.sh | 4 ++-- src/Runner.Common/Constants.cs | 3 ++- src/Runner.Listener/Program.cs | 11 +++++------ 6 files changed, 17 insertions(+), 37 deletions(-) diff --git a/src/Misc/layoutroot/run-helper.cmd.template b/src/Misc/layoutroot/run-helper.cmd.template index 160d9ab327c..081fad0b979 100644 --- a/src/Misc/layoutroot/run-helper.cmd.template +++ b/src/Misc/layoutroot/run-helper.cmd.template @@ -2,16 +2,6 @@ SET UPDATEFILE=update.finished "%~dp0\bin\Runner.Listener.exe" run %* SET RETURNCODE=%ERRORLEVEL% -SET OUTDATED_EXIT_CODE_NUM= - -if not "%ACTIONS_RUNNER_OUTDATED_EXIT_CODE%"=="" ( - set /a OUTDATED_EXIT_CODE_NUM=%ACTIONS_RUNNER_OUTDATED_EXIT_CODE% >NUL 2>NUL - if errorlevel 1 SET OUTDATED_EXIT_CODE_NUM= -) - -if not "%OUTDATED_EXIT_CODE_NUM%"=="" ( - if %OUTDATED_EXIT_CODE_NUM% LEQ 5 SET OUTDATED_EXIT_CODE_NUM= -) rem using `if %ERRORLEVEL% EQU N` instead of `if ERRORLEVEL N` rem `if ERRORLEVEL N` means: error level is N or MORE @@ -21,9 +11,9 @@ if %RETURNCODE% EQU 0 ( exit /b 0 ) -if not "%OUTDATED_EXIT_CODE_NUM%"=="" ( - if "%RETURNCODE%"=="%OUTDATED_EXIT_CODE_NUM%" ( - echo "Runner listener exit with outdated error code: %RETURNCODE%." +if "%ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE%"=="1" ( + if %RETURNCODE% EQU 7 ( + echo "Runner listener exit with deprecated version error code: %RETURNCODE%." exit /b %RETURNCODE% ) ) diff --git a/src/Misc/layoutroot/run-helper.sh.template b/src/Misc/layoutroot/run-helper.sh.template index 6b9ee5baa5a..dbdaba4fdb3 100755 --- a/src/Misc/layoutroot/run-helper.sh.template +++ b/src/Misc/layoutroot/run-helper.sh.template @@ -38,8 +38,8 @@ returnCode=$? if [[ $returnCode == 0 ]]; then echo "Runner listener exit with 0 return code, stop the service, no retry needed." exit 0 -elif [[ "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" =~ ^[0-9]+$ && "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" -gt 5 && "$returnCode" -eq "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" ]]; then - echo "Runner listener exit with outdated error code: ${returnCode}." +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." diff --git a/src/Misc/layoutroot/run.cmd b/src/Misc/layoutroot/run.cmd index 5be83b7dc9e..ae1e25a4e4a 100644 --- a/src/Misc/layoutroot/run.cmd +++ b/src/Misc/layoutroot/run.cmd @@ -22,25 +22,15 @@ rem **************************************************************************** copy "%~dp0run-helper.cmd.template" "%~dp0run-helper.cmd" /Y call "%~dp0run-helper.cmd" %* set RETURNCODE=%ERRORLEVEL% -set OUTDATED_EXIT_CODE_NUM= - -if not "%ACTIONS_RUNNER_OUTDATED_EXIT_CODE%"=="" ( - set /a OUTDATED_EXIT_CODE_NUM=%ACTIONS_RUNNER_OUTDATED_EXIT_CODE% >NUL 2>NUL - if errorlevel 1 set OUTDATED_EXIT_CODE_NUM= -) - -if not "%OUTDATED_EXIT_CODE_NUM%"=="" ( - if %OUTDATED_EXIT_CODE_NUM% LEQ 5 set OUTDATED_EXIT_CODE_NUM= -) if %RETURNCODE% EQU 1 ( echo "Restarting runner..." goto :launch_helper ) -if not "%OUTDATED_EXIT_CODE_NUM%"=="" ( - if "%RETURNCODE%"=="%OUTDATED_EXIT_CODE_NUM%" ( - echo "Exiting runner with outdated error code: %RETURNCODE%" +if "%ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE%"=="1" ( + if %RETURNCODE% EQU 7 ( + echo "Exiting runner with deprecated version error code: %RETURNCODE%" exit /b %RETURNCODE% ) ) diff --git a/src/Misc/layoutroot/run.sh b/src/Misc/layoutroot/run.sh index 8c5c68a3e15..960bdb87c4a 100755 --- a/src/Misc/layoutroot/run.sh +++ b/src/Misc/layoutroot/run.sh @@ -19,7 +19,7 @@ run() { returnCode=$? if [[ $returnCode -eq 2 ]]; then echo "Restarting runner..." - elif [[ -n "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" && "$returnCode" == "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" ]]; then + elif [[ "$ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE" == "1" && $returnCode -eq 7 ]]; then echo "Exiting runner..." exit "$returnCode" else @@ -45,7 +45,7 @@ runWithManualTrap() { returnCode=$? if [[ $returnCode -eq 2 ]]; then echo "Restarting runner..." - elif [[ -n "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" && "$returnCode" == "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" ]]; then + elif [[ "$ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE" == "1" && $returnCode -eq 6 ]]; then echo "Exiting runner..." exit "$returnCode" else diff --git a/src/Runner.Common/Constants.cs b/src/Runner.Common/Constants.cs index 347d36335c3..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,8 +278,8 @@ 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 RunnerOutdatedExitCode = "ACTIONS_RUNNER_OUTDATED_EXIT_CODE"; public static readonly string StepDebug = "ACTIONS_STEP_DEBUG"; } diff --git a/src/Runner.Listener/Program.cs b/src/Runner.Listener/Program.cs index 00d51652509..149f98ac3e4 100644 --- a/src/Runner.Listener/Program.cs +++ b/src/Runner.Listener/Program.cs @@ -143,7 +143,7 @@ private async static Task MainAsync(IHostContext context, string[] args) { terminal.WriteError($"An error occured: {e.Message}"); trace.Error(e); - return GetRunnerOutdatedExitCode(); + return GetRunnerVersionDeprecatedExitCode(); } catch (RunnerNotFoundException e) { @@ -159,13 +159,12 @@ private async static Task MainAsync(IHostContext context, string[] args) } } - private static int GetRunnerOutdatedExitCode() + private static int GetRunnerVersionDeprecatedExitCode() { - var configuredExitCode = Environment.GetEnvironmentVariable(Constants.Variables.Actions.RunnerOutdatedExitCode); - if (int.TryParse(configuredExitCode, NumberStyles.Integer, CultureInfo.InvariantCulture, out int exitCode) && - exitCode > 5) + var envValue = Environment.GetEnvironmentVariable(Constants.Variables.Actions.ReturnVersionDeprecatedExitCode); + if (envValue == "1") { - return exitCode; + return Constants.Runner.ReturnCode.RunnerVersionDeprecated; } return Constants.Runner.ReturnCode.TerminatedError; From 1509f36ca7863b314ec571e2cc5ebb66cfaa0b68 Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Thu, 12 Mar 2026 23:18:37 +0100 Subject: [PATCH 3/6] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Misc/layoutroot/run-helper.sh.template | 2 +- src/Runner.Listener/Program.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Misc/layoutroot/run-helper.sh.template b/src/Misc/layoutroot/run-helper.sh.template index dbdaba4fdb3..813c747355a 100755 --- a/src/Misc/layoutroot/run-helper.sh.template +++ b/src/Misc/layoutroot/run-helper.sh.template @@ -76,6 +76,6 @@ elif [[ $returnCode == 5 ]]; then echo "Runner listener exit with Session Conflict error, stop the service, no retry needed." exit 0 else - echo "NOO Exiting with unknown error code: ${returnCode}" + echo "Exiting with unknown error code: ${returnCode}" exit 0 fi diff --git a/src/Runner.Listener/Program.cs b/src/Runner.Listener/Program.cs index 149f98ac3e4..8e766a3ec10 100644 --- a/src/Runner.Listener/Program.cs +++ b/src/Runner.Listener/Program.cs @@ -141,7 +141,7 @@ 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 GetRunnerVersionDeprecatedExitCode(); } From 8391a4953977e379bfc5b890087dbadbe69b328d Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Thu, 12 Mar 2026 23:20:32 +0100 Subject: [PATCH 4/6] fix typo in exit code --- src/Misc/layoutroot/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Misc/layoutroot/run.sh b/src/Misc/layoutroot/run.sh index 960bdb87c4a..27b3cb404b2 100755 --- a/src/Misc/layoutroot/run.sh +++ b/src/Misc/layoutroot/run.sh @@ -45,7 +45,7 @@ runWithManualTrap() { returnCode=$? if [[ $returnCode -eq 2 ]]; then echo "Restarting runner..." - elif [[ "$ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE" == "1" && $returnCode -eq 6 ]]; then + elif [[ "$ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE" == "1" && $returnCode -eq 7 ]]; then echo "Exiting runner..." exit "$returnCode" else From 7ffc8cb0ceb7b05624cd4710687ef4269bb0ca3f Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Thu, 12 Mar 2026 23:22:30 +0100 Subject: [PATCH 5/6] fix typo --- src/Misc/layoutroot/run-helper.cmd.template | 21 ++++++++++----------- src/Misc/layoutroot/run.cmd | 9 ++++----- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Misc/layoutroot/run-helper.cmd.template b/src/Misc/layoutroot/run-helper.cmd.template index 081fad0b979..389280ef7c8 100644 --- a/src/Misc/layoutroot/run-helper.cmd.template +++ b/src/Misc/layoutroot/run-helper.cmd.template @@ -1,35 +1,34 @@ @echo off SET UPDATEFILE=update.finished "%~dp0\bin\Runner.Listener.exe" run %* -SET RETURNCODE=%ERRORLEVEL% rem using `if %ERRORLEVEL% EQU N` instead of `if ERRORLEVEL N` rem `if ERRORLEVEL N` means: error level is N or MORE -if %RETURNCODE% EQU 0 ( +if %ERRORLEVEL% EQU 0 ( echo "Runner listener exit with 0 return code, stop the service, no retry needed." exit /b 0 ) if "%ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE%"=="1" ( - if %RETURNCODE% EQU 7 ( - echo "Runner listener exit with deprecated version error code: %RETURNCODE%." - exit /b %RETURNCODE% + if %ERRORLEVEL% EQU 7 ( + echo "Runner listener exit with deprecated version error code: %ERRORLEVEL%." + exit /b %ERRORLEVEL% ) ) -if %RETURNCODE% EQU 1 ( +if %ERRORLEVEL% EQU 1 ( echo "Runner listener exit with terminated error, stop the service, no retry needed." exit /b 0 ) -if %RETURNCODE% EQU 2 ( +if %ERRORLEVEL% EQU 2 ( echo "Runner listener exit with retryable error, re-launch runner in 5 seconds." ping 127.0.0.1 -n 6 -w 1000 >NUL exit /b 1 ) -if %RETURNCODE% EQU 3 ( +if %ERRORLEVEL% EQU 3 ( rem Wait for 30 seconds or for flag file to exists for the ephemeral runner update process finish echo "Runner listener exit because of updating, re-launch runner after successful update" FOR /L %%G IN (1,1,30) DO ( @@ -43,7 +42,7 @@ if %RETURNCODE% EQU 3 ( exit /b 1 ) -if %RETURNCODE% EQU 4 ( +if %ERRORLEVEL% EQU 4 ( rem Wait for 30 seconds or for flag file to exists for the runner update process finish echo "Runner listener exit because of updating, re-launch runner after successful update" FOR /L %%G IN (1,1,30) DO ( @@ -57,10 +56,10 @@ if %RETURNCODE% EQU 4 ( exit /b 1 ) -if %RETURNCODE% EQU 5 ( +if %ERRORLEVEL% EQU 5 ( echo "Runner listener exit with Session Conflict error, stop the service, no retry needed." exit /b 0 ) -echo "Exiting after unknown error code: %RETURNCODE%" +echo "Exiting after unknown error code: %ERRORLEVEL%" exit /b 0 \ No newline at end of file diff --git a/src/Misc/layoutroot/run.cmd b/src/Misc/layoutroot/run.cmd index ae1e25a4e4a..d0a4052c9bc 100644 --- a/src/Misc/layoutroot/run.cmd +++ b/src/Misc/layoutroot/run.cmd @@ -21,17 +21,16 @@ rem **************************************************************************** :launch_helper copy "%~dp0run-helper.cmd.template" "%~dp0run-helper.cmd" /Y call "%~dp0run-helper.cmd" %* -set RETURNCODE=%ERRORLEVEL% -if %RETURNCODE% EQU 1 ( +if %ERRORLEVEL% EQU 1 ( echo "Restarting runner..." goto :launch_helper ) if "%ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE%"=="1" ( - if %RETURNCODE% EQU 7 ( - echo "Exiting runner with deprecated version error code: %RETURNCODE%" - exit /b %RETURNCODE% + if %ERRORLEVEL% EQU 7 ( + echo "Exiting runner with deprecated version error code: %ERRORLEVEL%" + exit /b %ERRORLEVEL% ) ) From 72128d9a7878fd008c6c8e85b25cf2796d23822d Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Fri, 13 Mar 2026 18:02:43 +0100 Subject: [PATCH 6/6] Convert to bool --- src/Runner.Listener/Program.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Runner.Listener/Program.cs b/src/Runner.Listener/Program.cs index 8e766a3ec10..d2923736402 100644 --- a/src/Runner.Listener/Program.cs +++ b/src/Runner.Listener/Program.cs @@ -161,8 +161,7 @@ private async static Task MainAsync(IHostContext context, string[] args) private static int GetRunnerVersionDeprecatedExitCode() { - var envValue = Environment.GetEnvironmentVariable(Constants.Variables.Actions.ReturnVersionDeprecatedExitCode); - if (envValue == "1") + if (StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable(Constants.Variables.Actions.ReturnVersionDeprecatedExitCode))) { return Constants.Runner.ReturnCode.RunnerVersionDeprecated; }