Created
November 17, 2015 03:32
-
-
Save barretts/0b0c3d0f366c85661697 to your computer and use it in GitHub Desktop.
npm install with retry on error from a Windows batch file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: I created this increase CI/CD stability when running in cloud VMs; npm install failing is such a sad test failure | |
:: general batch loop thanks @AlexZhidkov https://github.com/FeodorFitsner/BedfordHarbourBOM/blob/master/nuget-restore.cmd | |
:: pipe npm, search log thanks @Ricky-Brno http://stackoverflow.com/a/22492458/604861 | |
echo off | |
:: initiate the retry number | |
set retryNumber=0 | |
set maxRetries=3 | |
:RETRY | |
echo -------------------------------------- | |
echo execute npm install | |
cmd /c "npm install > npm-install.log 2>&1" | |
for /f %%a in ('type npm-install.log ^| find /c /i "npm err!"') do set err=%%a | |
if "%err%" EQU "0" GOTO YAY | |
set /a retryNumber=%retryNumber%+1 | |
echo error %err% was encountered during installation attempt %retryNumber% | |
if %retryNumber% LSS %maxRetries% (GOTO RETRY) | |
echo -------------------------------------- | |
echo npm install failed (T_T) | |
echo -------------------------------------- | |
EXIT /B 1 | |
:YAY | |
echo -------------------------------------- | |
echo npm install success (^^_^^)b | |
echo -------------------------------------- | |
EXIT /B 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment