From a0a69de4dfb4808a3393a55b9d683e00b3b2c450 Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Tue, 15 Sep 2020 11:05:13 -0700 Subject: [PATCH 1/5] Improve Win CI script with fail fast --- tools/internal_ci/helper_scripts/install_python38.ps1 | 8 +++++++- .../helper_scripts/prepare_build_windows.bat | 11 +++++++---- tools/internal_ci/windows/grpc_build_artifacts.bat | 2 +- tools/internal_ci/windows/grpc_build_packages.bat | 2 +- tools/internal_ci/windows/grpc_distribtests.bat | 2 +- .../windows/grpc_distribtests_standalone.bat | 2 +- tools/internal_ci/windows/grpc_run_tests_matrix.bat | 2 +- 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tools/internal_ci/helper_scripts/install_python38.ps1 b/tools/internal_ci/helper_scripts/install_python38.ps1 index 251eda0d76c..1c17dba3d66 100644 --- a/tools/internal_ci/helper_scripts/install_python38.ps1 +++ b/tools/internal_ci/helper_scripts/install_python38.ps1 @@ -4,6 +4,12 @@ Set-StrictMode -Version 2 $ErrorActionPreference = 'Stop' +trap { + $ErrorActionPreference = "Continue" + Write-Error $_ + exit 1 +} + # Avoid "Could not create SSL/TLS secure channel" [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 @@ -19,7 +25,7 @@ function Install-Python { # Downloads installer Write-Host "Downloading the Python installer: $PythonInstallerUrl => $PythonInstallerPath" - Invoke-WebRequest -Uri $PythonInstallerUrl -OutFile $PythonInstallerPath + Invoke-WebRequest -Uri $PythonInstallerUrl -OutFile $PythonInstallerPath -MaximumRetryCount 3 # Validates checksum $HashFromDownload = Get-FileHash -Path $PythonInstallerPath -Algorithm MD5 diff --git a/tools/internal_ci/helper_scripts/prepare_build_windows.bat b/tools/internal_ci/helper_scripts/prepare_build_windows.bat index 6b39d85ee1d..cda034adc91 100644 --- a/tools/internal_ci/helper_scripts/prepare_build_windows.bat +++ b/tools/internal_ci/helper_scripts/prepare_build_windows.bat @@ -29,20 +29,23 @@ netsh interface ip add dnsservers "Local Area Connection 8" 8.8.8.8 index=2 netsh interface ip add dnsservers "Local Area Connection 8" 8.8.4.4 index=3 @rem Needed for big_query_utils -python -m pip install google-api-python-client +python -m pip install google-api-python-client || goto :error @rem C# prerequisites: Install dotnet SDK -powershell -File src\csharp\install_dotnet_sdk.ps1 +powershell -File src\csharp\install_dotnet_sdk.ps1 || goto :error set PATH=%LOCALAPPDATA%\Microsoft\dotnet;%PATH% @rem Install Python 3.8.0 @rem NOTE(lidiz): Python installer process may live longer than expected, and @rem has other side effects. It needs to be installed last to reduce impact. -powershell -File tools\internal_ci\helper_scripts\install_python38.ps1 +powershell -File tools\internal_ci\helper_scripts\install_python38.ps1 || goto :error @rem Disable some unwanted dotnet options set NUGET_XMLDOC_MODE=skip set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true set DOTNET_CLI_TELEMETRY_OPTOUT=true -git submodule update --init +git submodule update --init || goto :error + +:error +exit /b 1 diff --git a/tools/internal_ci/windows/grpc_build_artifacts.bat b/tools/internal_ci/windows/grpc_build_artifacts.bat index be47fe670b6..473b6ee9822 100644 --- a/tools/internal_ci/windows/grpc_build_artifacts.bat +++ b/tools/internal_ci/windows/grpc_build_artifacts.bat @@ -19,7 +19,7 @@ choco install nasm -y --limit-output @rem enter repo root cd /d %~dp0\..\..\.. -call tools/internal_ci/helper_scripts/prepare_build_windows.bat +call tools/internal_ci/helper_scripts/prepare_build_windows.bat || exit /b 1 python tools/run_tests/task_runner.py -f artifact windows -j 4 set RUNTESTS_EXITCODE=%errorlevel% diff --git a/tools/internal_ci/windows/grpc_build_packages.bat b/tools/internal_ci/windows/grpc_build_packages.bat index 19a805adfc2..a5bffb28c24 100644 --- a/tools/internal_ci/windows/grpc_build_packages.bat +++ b/tools/internal_ci/windows/grpc_build_packages.bat @@ -15,7 +15,7 @@ @rem enter repo root cd /d %~dp0\..\..\.. -call tools/internal_ci/helper_scripts/prepare_build_windows.bat +call tools/internal_ci/helper_scripts/prepare_build_windows.bat || exit /b 1 @rem Move artifacts generated by the previous step in the build chain. powershell -Command "mv %KOKORO_GFILE_DIR%\github\grpc\artifacts input_artifacts" diff --git a/tools/internal_ci/windows/grpc_distribtests.bat b/tools/internal_ci/windows/grpc_distribtests.bat index 72d7076ec90..6b74972f359 100644 --- a/tools/internal_ci/windows/grpc_distribtests.bat +++ b/tools/internal_ci/windows/grpc_distribtests.bat @@ -15,7 +15,7 @@ @rem enter repo root cd /d %~dp0\..\..\.. -call tools/internal_ci/helper_scripts/prepare_build_windows.bat +call tools/internal_ci/helper_scripts/prepare_build_windows.bat || exit /b 1 @rem Move packages generated by the previous step in the build chain. powershell -Command "mv %KOKORO_GFILE_DIR%\github\grpc\artifacts input_artifacts" diff --git a/tools/internal_ci/windows/grpc_distribtests_standalone.bat b/tools/internal_ci/windows/grpc_distribtests_standalone.bat index 80334674144..e0722dbf375 100644 --- a/tools/internal_ci/windows/grpc_distribtests_standalone.bat +++ b/tools/internal_ci/windows/grpc_distribtests_standalone.bat @@ -15,7 +15,7 @@ @rem enter repo root cd /d %~dp0\..\..\.. -call tools/internal_ci/helper_scripts/prepare_build_windows.bat +call tools/internal_ci/helper_scripts/prepare_build_windows.bat || exit /b 1 python tools/run_tests/task_runner.py -f distribtest windows cpp -j 4 set RUNTESTS_EXITCODE=%errorlevel% diff --git a/tools/internal_ci/windows/grpc_run_tests_matrix.bat b/tools/internal_ci/windows/grpc_run_tests_matrix.bat index c6277d0929e..01d1f811034 100644 --- a/tools/internal_ci/windows/grpc_run_tests_matrix.bat +++ b/tools/internal_ci/windows/grpc_run_tests_matrix.bat @@ -15,7 +15,7 @@ @rem enter repo root cd /d %~dp0\..\..\.. -call tools/internal_ci/helper_scripts/prepare_build_windows.bat +call tools/internal_ci/helper_scripts/prepare_build_windows.bat || exit /b 1 python tools/run_tests/run_tests_matrix.py %RUN_TESTS_FLAGS% set RUNTESTS_EXITCODE=%errorlevel% From 17ae39d9d16da74708f0aa303c7a296edd99d13b Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Tue, 15 Sep 2020 14:57:20 -0700 Subject: [PATCH 2/5] Invoke-WebRequest started support retry in 2018; Kokoro VM is too old --- tools/internal_ci/helper_scripts/install_python38.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/internal_ci/helper_scripts/install_python38.ps1 b/tools/internal_ci/helper_scripts/install_python38.ps1 index 1c17dba3d66..26d8ed8bdc0 100644 --- a/tools/internal_ci/helper_scripts/install_python38.ps1 +++ b/tools/internal_ci/helper_scripts/install_python38.ps1 @@ -25,7 +25,7 @@ function Install-Python { # Downloads installer Write-Host "Downloading the Python installer: $PythonInstallerUrl => $PythonInstallerPath" - Invoke-WebRequest -Uri $PythonInstallerUrl -OutFile $PythonInstallerPath -MaximumRetryCount 3 + Invoke-WebRequest -Uri $PythonInstallerUrl -OutFile $PythonInstallerPath # Validates checksum $HashFromDownload = Get-FileHash -Path $PythonInstallerPath -Algorithm MD5 From 83b60606d8b83acfbc9a2586b6769edc21f5deca Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Tue, 15 Sep 2020 15:03:38 -0700 Subject: [PATCH 3/5] Also add return code alternating to the .net install script --- src/csharp/install_dotnet_sdk.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/csharp/install_dotnet_sdk.ps1 b/src/csharp/install_dotnet_sdk.ps1 index 57328fa9981..1685e417822 100644 --- a/src/csharp/install_dotnet_sdk.ps1 +++ b/src/csharp/install_dotnet_sdk.ps1 @@ -4,6 +4,12 @@ Set-StrictMode -Version 2 $ErrorActionPreference = 'Stop' +trap { + $ErrorActionPreference = "Continue" + Write-Error $_ + exit 1 +} + # avoid "Unknown error on a send" in Invoke-WebRequest [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 From 1b79729b1788f784648395c149e4f42fa6495dcf Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Tue, 15 Sep 2020 15:38:00 -0700 Subject: [PATCH 4/5] Stop execution --- tools/internal_ci/helper_scripts/prepare_build_windows.bat | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/internal_ci/helper_scripts/prepare_build_windows.bat b/tools/internal_ci/helper_scripts/prepare_build_windows.bat index cda034adc91..1114baebb04 100644 --- a/tools/internal_ci/helper_scripts/prepare_build_windows.bat +++ b/tools/internal_ci/helper_scripts/prepare_build_windows.bat @@ -48,4 +48,5 @@ set DOTNET_CLI_TELEMETRY_OPTOUT=true git submodule update --init || goto :error :error +popd exit /b 1 From 751d152e2c5d73ad138616a4aab4e17a83a29ce9 Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Tue, 15 Sep 2020 16:05:36 -0700 Subject: [PATCH 5/5] Goto :EOF --- tools/internal_ci/helper_scripts/prepare_build_windows.bat | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/internal_ci/helper_scripts/prepare_build_windows.bat b/tools/internal_ci/helper_scripts/prepare_build_windows.bat index 1114baebb04..8f2ded551b0 100644 --- a/tools/internal_ci/helper_scripts/prepare_build_windows.bat +++ b/tools/internal_ci/helper_scripts/prepare_build_windows.bat @@ -47,6 +47,7 @@ set DOTNET_CLI_TELEMETRY_OPTOUT=true git submodule update --init || goto :error +goto :EOF + :error -popd exit /b 1