How to make GitLab's CI/CD job fail based on text in console output?

99封情书 提交于 2020-06-29 03:54:14

问题


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

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.

Any suggestions?


回答1:


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


来源:https://stackoverflow.com/questions/57416222/how-to-make-gitlabs-ci-cd-job-fail-based-on-text-in-console-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!