我遇到了有关GitlabCI的问题,希望有人可以帮助我解决这个问题。
问题是,我想运行一个Shell脚本,以在触发作业时比较GitlabCI运行程序中的源分支和目标分支。 .gitlab-ci.yml
看起来像这样。
testJob: // the name of the CI/CD job
only:
refs:
- merge_requests
change:
- a/json/folder/*
before_script:
... // some action
script:
- bash ./xxx.sh
如果这是合并请求,并且其中包含一堆json文件的文件夹中有任何更改,则将触发此作业。然后,它将运行shell脚本。
在shell脚本中,我将比较源分支和目标分支以获得修改后的json文件的列表,因此我在shell脚本中运行此命令。
current_branch=`git rev-parse --abbrev-ref HEAD` // to get the current branch name, i.e. the source branch
diff_message=`git diff --name-only --diff-filter=AM origin/develop..origin/$CI_COMMIT_REF_NAME`
由于某些原因,目标分支将被固定开发。这段代码在本地运行良好,但在GitlabCI运行程序上崩溃。因此,我去了Gitlab,看看发生了什么,并且看到了如下的错误消息。
fatal: ambiguous argument 'origin/develop..origin/fix/json': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
我的朋友告诉我,运行程序将仅加载当前分支(合并请求的源分支),而不加载目标分支(在这种情况下为开发)。是真的吗如果是真的,我该如何让GitlabCI运行程序加载它。而且如果不可能,我是否还有其他选择可以获取两个分支之间的已修改json文件列表?
谢谢。