我正在对提交了 terragrunt.hcl
文件的目录运行合规性扫描。
我希望我的 .gitlab-ci.yaml
管道仅在目录及其子目录中这个特定文件 "terragrunt.hcl" 发生更改时触发,而且不会因其他任何提交而触发。使用GitLab的CI/CD工具是否有办法实现这一点,或者编写一个自定义构建脚本会更容易呢?
下面这条bash命令可以实现我的需求,但问题是它仍然在任何提交时触发管道,而我只想在那个特定的 terragrunt.hcl
上构建:
for i in $(git diff-tree --no-commit-id --name-only -r $CI_COMMIT_SHA | xargs -n 1 dirname | uniq); do cd /scripts && ./run.sh /path/to/$i; done
我找到了这个资源:GitLab CI/CD: Run jobs only when files in a specific directory have changed,并且正在对其进行测试,但我需要额外的帮助!我离成功非常接近!!
if
语句就可以了 :) 由于我需要完整路径,这个命令git diff-tree --no-commit-id --name-only -r $CI_COMMIT_SHA
列出了我提交的所有文件及其完整路径,但我只想要那些已经修改了terragrunt.hcl
的提交记录。我知道我的if
语句是错误的,但只是为了让你明白我想要实现的目标:- if: git diff-tree --no-commit-id --name-only -r $CI_COMMIT_SHA =~ /terragrunt.hcl/
。 - kddiji