我如何在gitlabci管道中知道更新的文件 [英] How can I know the updated file during the gitlabci pipeline
问题描述
在gitlab管道中(在分支上的每次提交之后触发),我想知道提交涉及哪些文件,以便对每个文件应用特定的bash脚本.
我目前在gitlabci.yaml
文件中使用以下代码:
During the gitlab pipeline (triggered after each commit on my branch), I want to know which files are concerned by the commit in order to apply specific bash script regarding each file.
I'm currently using the following code in my gitlabci.yaml
file:
- export DIFF=$(git show --stat HEAD)
- ./myBashScript.sh
然后我在bash脚本中使用$DIFF
.
但是有更好的方法吗? (我正在使用本地gitlab 10.8)
Then I'm using $DIFF
in my bash script.
But is there a better approach? (I'm using a local gitlab 10.8)
推荐答案
您可以使用现有的CI变量,以执行以下操作来检索已更改文件的列表:
You can use already existing CI variables to do something like this to retrieve the list of changed files:
git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA
CI_BUILD_BEFORE_SHA和CI_BUILD_REF,如果您正在运行在Gitlab 8.x上
CI_BUILD_BEFORE_SHA and CI_BUILD_REF if you are running on Gitlab 8.x
这篇关于我如何在gitlabci管道中知道更新的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!