我如何在gitlabci管道中知道更新的文件 [英] How can I know the updated file during the gitlabci pipeline

查看:758
本文介绍了我如何在gitlabci管道中知道更新的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆