简体   繁体   中英

use bash case statement in gitlab ci/cd

so i have a pipeline that checks 2 repos every 24 hours and pushes changes to a 3rd repo. the pipeline looks like this:

- git  fetch $CHEATSHEETS
- git  fetch $BASH_ONELINER
- git add -A
- git commit -m "Update has been successful" || echo "error"
- git push $TOKEN_AND_REPO HEAD:master

my problem with that is i'm never going to see any error in the pipeline if there's an error like a merge conflict, for example. so i was thinking to use a case for comitting, something like this:

TEST=2; case "${TEST}" in "1") echo "one";; "2") echo "The commit has failed";; *) echo "Error";; esac

my question is would something like this work in gitlab ci/cd pipeline and if so - how should it be implemented?

thanks in advance.

You seem to want to do:

- git  fetch $CHEATSHEETS
- git  fetch $BASH_ONELINER
- git add -A
- if git diff-index --cached --quiet HEAD; then
     echo "Nothing to commit... exiting" &&
     exit 0
  fi
- git commit -m "Update has been successful"
- git push $TOKEN_AND_REPO HEAD:master

which is unrelated to using case . You can use case normally in gitlab-ci pipeline, just like in shell. See How do I programmatically determine if there are uncommitted changes?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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