Exit with specified exit code when runner is outdated (#4285)
Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -10,6 +10,13 @@ if %ERRORLEVEL% EQU 0 (
|
|||||||
exit /b 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 (
|
if %ERRORLEVEL% EQU 1 (
|
||||||
echo "Runner listener exit with terminated error, stop the service, no retry needed."
|
echo "Runner listener exit with terminated error, stop the service, no retry needed."
|
||||||
exit /b 0
|
exit /b 0
|
||||||
|
|||||||
@@ -34,11 +34,13 @@ fi
|
|||||||
|
|
||||||
updateFile="update.finished"
|
updateFile="update.finished"
|
||||||
"$DIR"/bin/Runner.Listener run $*
|
"$DIR"/bin/Runner.Listener run $*
|
||||||
|
|
||||||
returnCode=$?
|
returnCode=$?
|
||||||
if [[ $returnCode == 0 ]]; then
|
if [[ $returnCode == 0 ]]; then
|
||||||
echo "Runner listener exit with 0 return code, stop the service, no retry needed."
|
echo "Runner listener exit with 0 return code, stop the service, no retry needed."
|
||||||
exit 0
|
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
|
elif [[ $returnCode == 1 ]]; then
|
||||||
echo "Runner listener exit with terminated error, stop the service, no retry needed."
|
echo "Runner listener exit with terminated error, stop the service, no retry needed."
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
@@ -25,7 +25,14 @@ call "%~dp0run-helper.cmd" %*
|
|||||||
if %ERRORLEVEL% EQU 1 (
|
if %ERRORLEVEL% EQU 1 (
|
||||||
echo "Restarting runner..."
|
echo "Restarting runner..."
|
||||||
goto :launch_helper
|
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
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ run() {
|
|||||||
returnCode=$?
|
returnCode=$?
|
||||||
if [[ $returnCode -eq 2 ]]; then
|
if [[ $returnCode -eq 2 ]]; then
|
||||||
echo "Restarting runner..."
|
echo "Restarting runner..."
|
||||||
|
elif [[ "$ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE" == "1" && $returnCode -eq 7 ]]; then
|
||||||
|
echo "Exiting runner..."
|
||||||
|
exit "$returnCode"
|
||||||
else
|
else
|
||||||
echo "Exiting runner..."
|
echo "Exiting runner..."
|
||||||
exit 0
|
exit 0
|
||||||
@@ -42,6 +45,9 @@ runWithManualTrap() {
|
|||||||
returnCode=$?
|
returnCode=$?
|
||||||
if [[ $returnCode -eq 2 ]]; then
|
if [[ $returnCode -eq 2 ]]; then
|
||||||
echo "Restarting runner..."
|
echo "Restarting runner..."
|
||||||
|
elif [[ "$ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE" == "1" && $returnCode -eq 7 ]]; then
|
||||||
|
echo "Exiting runner..."
|
||||||
|
exit "$returnCode"
|
||||||
else
|
else
|
||||||
echo "Exiting runner..."
|
echo "Exiting runner..."
|
||||||
# Unregister signal handling before exit
|
# Unregister signal handling before exit
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ namespace GitHub.Runner.Common
|
|||||||
// and the runner should be restarted. This is a temporary code and will be removed in the future after
|
// 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.
|
// the runner is migrated to runner admin.
|
||||||
public const int RunnerConfigurationRefreshed = 6;
|
public const int RunnerConfigurationRefreshed = 6;
|
||||||
|
public const int RunnerVersionDeprecated = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Features
|
public static class Features
|
||||||
@@ -277,6 +278,7 @@ namespace GitHub.Runner.Common
|
|||||||
public static readonly string AllowUnsupportedCommands = "ACTIONS_ALLOW_UNSECURE_COMMANDS";
|
public static readonly string AllowUnsupportedCommands = "ACTIONS_ALLOW_UNSECURE_COMMANDS";
|
||||||
public static readonly string AllowUnsupportedStopCommandTokens = "ACTIONS_ALLOW_UNSECURE_STOPCOMMAND_TOKENS";
|
public static readonly string AllowUnsupportedStopCommandTokens = "ACTIONS_ALLOW_UNSECURE_STOPCOMMAND_TOKENS";
|
||||||
public static readonly string RequireJobContainer = "ACTIONS_RUNNER_REQUIRE_JOB_CONTAINER";
|
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 RunnerDebug = "ACTIONS_RUNNER_DEBUG";
|
||||||
public static readonly string StepDebug = "ACTIONS_STEP_DEBUG";
|
public static readonly string StepDebug = "ACTIONS_STEP_DEBUG";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,9 +141,9 @@ namespace GitHub.Runner.Listener
|
|||||||
}
|
}
|
||||||
catch (AccessDeniedException e) when (e.ErrorCode == 1)
|
catch (AccessDeniedException e) when (e.ErrorCode == 1)
|
||||||
{
|
{
|
||||||
terminal.WriteError($"An error occured: {e.Message}");
|
terminal.WriteError($"An error occurred: {e.Message}");
|
||||||
trace.Error(e);
|
trace.Error(e);
|
||||||
return Constants.Runner.ReturnCode.TerminatedError;
|
return GetRunnerVersionDeprecatedExitCode();
|
||||||
}
|
}
|
||||||
catch (RunnerNotFoundException e)
|
catch (RunnerNotFoundException e)
|
||||||
{
|
{
|
||||||
@@ -159,6 +159,16 @@ namespace GitHub.Runner.Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
private static void LoadAndSetEnv()
|
||||||
{
|
{
|
||||||
var binDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
var binDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
|
|||||||
Reference in New Issue
Block a user