0

I have a Jenkins Pipeline job (Windows) where I run the following 'bat' command inside a steps block:

    bat '''cd .\\ProductName\\src\\ProductName.UI
echo Start: npm install
npm install -f'''

Currently, there is a situation where this command fails, but the build step does not fail. So, seemingly, an error code is not returned to Jenkins.

To be clear, I am not asking for help to fix this particular error. I am asking for help to make the error notify Jenkins that the build step has failed.

To give a bit of context, here is an excerpt of the 'npm install' error:

gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2

gyp verb `which` failed   code: 'ENOENT' }
gyp verb could not find "python". checking python launcher 
gyp verb could not find "python". guessing location 
gyp verb ensuring that file exists: C:\Python27\python.exe
gyp ERR! configure error 
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.

gyp ERR! node -v v10.3.0
gyp ERR! node-gyp -v v3.7.0
gyp ERR! not ok 
Build failed with error code: 1

So does npm install return an error code which can in turn be returned from the batch job? Or is there something else that I am missing?

Ola Eldøy
  • 5,720
  • 7
  • 49
  • 82
  • maybe ```bat ... npm install -f exit /b %ERRORLEVEL% ``` https://stackoverflow.com/questions/734598/how-do-i-make-a-batch-file-terminate-upon-encountering-an-error – markm Jul 24 '18 at 08:44
  • Possible duplicate of [How to make jenkins fail at a failing windows batch command?](https://stackoverflow.com/questions/25121360/how-to-make-jenkins-fail-at-a-failing-windows-batch-command) – apr_1985 Jul 24 '18 at 08:45
  • 1
    I found, from the question below, that npm is a batch file itself, so unless it is called with the 'call' command, the rest of the batch script is not executed. Unfortunately, %ERRORLEVEL% is 0 after running a failing 'call npm install'. So that check does not solve things directly. https://stackoverflow.com/questions/16856826/jenkins-script-quitting-prematurely-when-using-npm-install-on-windows – Ola Eldøy Jul 24 '18 at 10:32

0 Answers0