nodejs failed but bash doesn't stop even I have set -e

Viewed 283

I run a script in nodejs that trigger by bash that run by Jenkins pipeline.

The problem is the pipeline doesn't stop when the error happens. it should not run "echo git add ."

I add set -e - but seems that not work in this case.

What I can do to stop the execute in bash because error in the npm/node?

In Jenkins:

 stage('Deploy') {
  sh './scripts/deploy.sh'
 }

In deploy.sh:

#!/bin/bash
set -e
npm run prepare-version

echo "git add ."

In package.json:

"scripts": { "prepare-version": "node ./scripts/prepare.js" }

prepare.js:

 (async() => { 
   throw new Error('bug!!!');
 })();

enter image description here

1 Answers

Your node.js file failed, though bash script executed it succesfully. Read and compare status code:

#!/bin/bash
set -e
npm run prepare-version

[[ $? != 0 ]] && exit;
echo 'git add .'
Related