问题
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