简体   繁体   English

在 gitlab ci/cd 中使用 bash 案例语句

[英]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.所以我有一个管道,每 24 小时检查 2 个 repos 并将更改推送到第 3 个 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?我的问题是在 gitlab ci/cd 管道中是否会有类似的工作,如果是这样 - 它应该如何实施?

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 .这与用case无关。 You can use case normally in gitlab-ci pipeline, just like in shell.您可以在 gitlab-ci 管道中正常使用case ,就像在 shell 中一样。 See How do I programmatically determine if there are uncommitted changes?请参阅如何以编程方式确定是否存在未提交的更改?

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

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