如何基于控制台输出中的文本使GitLab的CI/CD作业失败? [英] How to make GitLab's CI/CD job fail based on text in console output?

查看:307
本文介绍了如何基于控制台输出中的文本使GitLab的CI/CD作业失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Lerna 来管理多包存储库,在我的部署工作中,我使用Lerna的命令.对我来说,如果在软件包中更改了代码,则应始终向我们的Artifactory发布新版本,如果没有发布任何内容,则作业将失败,但是即使没有软件包,publish命令也会以成功代码(我猜是0代码)退出发布位置:

I am using Lerna to manage a multipackage repository and in my deployment job I use Lerna's publish command. For me if code is changed in a package it should always publish a new version to our Artifactory and fail the job if nothing was published, but the publish command will exit with success code (I guess it's 0 code) even when no packages where published:

$ npx lerna publish from-package --yes

lerna notice cli v3.13.1
lerna info ci enabled
lerna notice from-package No unpublished release found
lerna success No changed packages to publish 
Job succeeded

我当时想我可以通过将输出传递到GREP并搜索文本"No changed packages to publish"来解决此问题,但是然后不确定如何在找到该文本时告诉Gitlab使作业失败.

I was thinking I could workaround this by piping the output to GREP and searching for the text "No changed packages to publish" but then not sure how to tell Gitlab to make the job fail when that text is found.

有什么建议吗?

推荐答案

如果在bash脚本中调用npx,则可以捕获文本并以非0状态退出:

If you are calling npx in a bash script, you can catch the text and exit with non-0 status:

lerna_output=$(npx lerna publish from-package --yes) || exit $?
nothing_published=$(echo $lerna_output | grep 'No changed packages to publish')
if [ "$nothing_published" != "" ]; then
    echo $lerna_output
    exit 1
fi

这篇关于如何基于控制台输出中的文本使GitLab的CI/CD作业失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆