GitLab CI,monorepo和功能分支 [英] GitLab CI, monorepo and feature branch

查看:165
本文介绍了GitLab CI,monorepo和功能分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GitLab中有一个采用功能分支方法的monorepo.

I have a monorepo in GitLab with a Feature Branch approach.

我要实现的目标是启动与包含更改后的文件的目录相关联的管道部分.所以我的.gitlab-ci.yml看起来像:

What I'm trying to achieve is to launch the part of the pipeline associated to the directory containing the altered files. So my .gitlab-ci.yml looks like :

job1:
  stage: build
  script:
    - ...
  only:
    changes:
      - myparentdir/dir1/*

job2:
  stage: build
  script:
    - ...
  only:
    changes:
      - myparentdir/dir2/*

  1. 从develop创建一个新分支
  2. 在此分支上提交myparentdir/dir2/test.txt
  3. 管道将启动每个构建作业!

在使用新功能分支时,GitLab似乎正在考虑更改每个文件.

It seems like GitLab is considering every files as altered when working with a new feature branch.

您知道任何解决方法吗?

Do you know any workaround?

推荐答案

Gitlab ci始终将新分支的changes视为true.原因是他们无法决定要与之进行比较.

Gitlab ci always treats changes for new branches as true. The reason is that they can't decide what to compare against.

这意味着对于新分支的第一个管道,将构建所有内容.

what this means is that for the first pipeline of a new branch, everything will be built.

请参见功能请求以获得更多详细信息.

See the feature request for more details.

但是,有一个相当新的功能,称为合并请求的管道-对合并请求运行一个阶段. 此处是通过merge_requests实现changes的功能请求.它已经合并,但是我不确定它是否已经发布. (里程碑是11.9-下一个版本)

But, there is a fairly new feature called Pipelines for merge requests - that runs a stage on merge requests. Here is the feature request that implements changes with merge_requests. It's merged, but I'm not sure if it's already released. (the milestone is 11.9 - the next release)

同时,您可以自己实现它-您可以添加一个阶段来比较更改(git diff)并决定是否运行下一阶段:

In the meantime you can implement it yourself - You can add a stage that compares the changes (git diff) and decides whether to run the next stage:

.store_diff_from_main: &store_diff_from_main |
  git diff --name-only origin/master...HEAD > "${DIFF_FILE}"
  git diff --name-only HEAD~1 >> "${DIFF_FILE}"

.skip_stage: &skip_stage_condition |
  echo Checking for changes in ${STAGE_PATHS}, changed files
  # https://coderwall.com/p/gecfwa/git-diff-vs
  cat .diff-from-master
  # also cover merge squash cases
  if ! (cat ${DIFF_FILE} | grep -E "${STAGE_PATHS}"); then
    echo "Skipping stage ..."
    exit 0
  fi

这篇关于GitLab CI,monorepo和功能分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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