Gitlab CI-如何列出更改并将其放入管道变量的目录

发布于 2025-02-06 03:48:58 字数 515 浏览 1 评论 0原文

是否可以自动检测包含在提交中具有更改的文件的顶级目录,并将其添加到我可以在另一个阶段使用的变量?

假设我有一个项目:

  • folder1/file [1-3] .txt
  • folder2/folder3/file4.txt

如果提交提交file1.txt,我想定义一个等于“ folder1”的变量。

   variables:
   - $MYVAR == "folder1"

如果提交修改File4.txt,我想定义一个等于“ folder2”的变量。

   variables:
   - $MYVAR == "folder2"

在不同文件夹中对多个文件的修改不应发生。

然后在管道的另一个阶段使用该变量:

MEP:
  stage: deploy
  script:
    - echo $MYVAR

这是可能的吗?

Is it possible to automatically detect the top-level directory that contains file that have changes in the commit, and add this to a variable that i can use in another stage ?

Let's say i have a project with :

  • folder1/file[1-3].txt
  • folder2/folder3/file4.txt

If the commit modify file1.txt, i would like to define a variable that is equal to "folder1".

   variables:
   - $MYVAR == "folder1"

If the commit modify file4.txt, i would like to define a variable that is equal to "folder2".

   variables:
   - $MYVAR == "folder2"

Modification to multiple file in different folder should not happen.

And then use that variable in another stage of the pipeline :

MEP:
  stage: deploy
  script:
    - echo $MYVAR

Would that be possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄离 2025-02-13 03:48:59

您可以有条件地使用规则定义变量:变量: - 规则可以使用规则:更改:来确定特定文件是否更改。

myjob:
  variables:
    MY_VAR: "default value"

  rules:
    - changes:
        - folder1/file[1-3].txt
      variables:
        MY_VAR: folder1  # override MY_VAR when this rule matches
    - changes:
        - folder2/folder3/file4.txt
      variables:
        MY_VAR: folder2

请记住,只有1个规则匹配的任何给定的工作/管道。

You can conditionally define variables with rules:variables: -- rules can use rules:changes: to determine if particular files changed.

myjob:
  variables:
    MY_VAR: "default value"

  rules:
    - changes:
        - folder1/file[1-3].txt
      variables:
        MY_VAR: folder1  # override MY_VAR when this rule matches
    - changes:
        - folder2/folder3/file4.txt
      variables:
        MY_VAR: folder2

Keep in mind only 1 rule matches for any given job/pipeline.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文