简体   繁体   English

如何从node.js失败gitlab-ci作业

[英]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. 在giltab ci作业中,我正在运行一个node.js脚本,在那里我评估一些条件,以及我可能想要强制作业失败的地方。

The script is written in es6 and is ran with yarn and babel-node yarn babel-node ./script-in-es6.js . 脚本是用es6编写的,用纱线和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? 有没有一种正确的方法可以从node.js成功地使gitlab中的作业失败?

If your script really does return exit code 1, try this: 如果您的脚本确实返回退出代码1,请尝试以下操作:

script:
  - <run your script> || export RES="$?"
  - exit $RES

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM