How to fail a gitlab-ci job from node.js

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')

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?

1 Like

Same problem here. Did you managed already to deal with it?