GitLab CI/CD:仅当特定目录中的文件已更改时才运行作业 [英] GitLab CI/CD: Run jobs only when files in a specific directory have changed

查看:41
本文介绍了GitLab CI/CD:仅当特定目录中的文件已更改时才运行作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当且仅当存储库的特定目录中的文件已更改时,我才想在.gitlab-ci.yaml上运行特定作业.有没有办法使用gilab的ci/cd工具来做到这一点,或者只是运行自定义的构建脚本会更容易吗?

I would like to run specific jobs on the .gitlab-ci.yaml if and only if files within specific directories of the repository have changed. Is there a way to do this with gilab's ci/cd tooling or would it be easier just to run a custom build script?

推荐答案

更改GitLab 11.4中引入的策略.

Changes policy introduced in GitLab 11.4.

例如:

docker build:
  script: docker build -t my-image:$CI_COMMIT_REF_SLUG .
  only:
    changes:
      - Dockerfile
      - docker/scripts/*
      - dockerfiles/**/*
      - more_scripts/*.{rb,py,sh}

在上述情况下,如果您要将对GitLab的多个提交推送到现有分支,则GitLab会创建并触发docker build作业,前提是其中一个提交包含对以下任意一项的更改:

In the scenario above, if you are pushing multiple commits to GitLab to an existing branch, GitLab creates and triggers the docker build job, provided that one of the commits contains changes to either:

  • Dockerfile文件.
  • docker/scripts/目录中的任何文件.
  • dockerfiles目录中的任何文件和子目录.
  • more_scripts目录中具有rb,py,sh扩展名的任何文件.

您可以在文档

这篇关于GitLab CI/CD:仅当特定目录中的文件已更改时才运行作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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