5

On a giltab ci job I am running a node.js script where I evaluate some conditions, and where I might want to force the job to fail.

The script is written in es6 and is ran with yarn and babel-node yarn babel-node ./script-in-es6.js.

When the condition fails I would like the job to fail. I have tried the following:

throw new Error('job failed')
process.exit(1)
require('shelljs').exit(1)

But none of these commands are enough to fail the job, it always succeeds. Is there a proper way to successfully fail a job in gitlab from node.js?

Marcio Oliveira
  • 791
  • 1
  • 5
  • 18
  • I passed through this issue and I can say that process.exit(1) works. If your program does return a zero exit code is because a previous line is exiting before your process.exit(1) does. To check which line is causing this place your process.exit(1) to the first line, check if it works and then move it to the next lines until it stops working. You will identify which line is causing your exit 0. – José Manuel Blasco May 05 '20 at 07:27

1 Answers1

0

If your script really does return exit code 1, try this:

script:
  - <run your script> || export RES="$?"
  - exit $RES
Amityo
  • 5,635
  • 4
  • 22
  • 29