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

查看:15
本文介绍了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天全站免登陆