GitLab CI / CD:仅当特定目录中的文件已更改时才运行作业

时间:2018-08-02 19:42:44

标签: git continuous-integration gitlab

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

4 个答案:

答案 0 :(得分:1)

您可以执行以下操作:

trigger_documentation:
  image: alpine:3.8
  stage: trigger_documentation
  script:
    - apk update && apk add git curl bash
    - |
      if git diff --name-only --diff-filter=ADMR @~..@ |grep ^doc/; then
            echo "triggering..."
      fi

答案 1 :(得分:1)

现在可以了:

rules:
    - changes:
      - package.json
      - yarn.lock
    - exists: 
      - node_modules
      when: never
    - when: always

您可以检查文件更改或检查是否存在。 Rules Documentation

答案 2 :(得分:0)

尚不可能,请参见https://gitlab.com/gitlab-org/gitlab-ce/issues/19232

另一方面,如果您准备CI的自定义脚本,则可以根据修改的文件/路径来限制CI的操作。

答案 3 :(得分:0)

更改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作业,前提是其中一个提交包含对以下任一更改的更改:

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

您可以在documentation

中阅读更多内容
相关问题