简体   繁体   English

在管道事件源中使用“分支推送”方法计算“仅:更改:” - 合并请求

[英]Using the "branch push" method of calculate "only: changes:" in pipeline event source - merge-request

The behaviour of "only: changes:" pipeline's rules in merge-request and in push branches event are different: “仅:更改:”管道在合并请求和推送分支事件中的行为是不同的:

  • During the push event changes calculates relative on previous commit.在推送事件期间,更改计算相对于先前提交。

  • During the push in merge-request event changes calculates between the current branch and the target branch.在合并请求事件的推送期间,计算当前分支和目标分支之间的变化。 (To tell the truth, if target branch is also a source branch, this is a not a HEAD commit of target branch, this is a merge-base commit - fork point or last merge commit with source branch ) (说实话,如果目标分支也是源分支,这不是目标分支的 HEAD 提交,这是合并基础提交 - 分叉点或与源分支的最后合并提交)

So, if the branch have some code and some tests.所以,如果分支有一些代码和一些测试。 Some stages relative from catalog of code, and test stages relative from test catalog.一些阶段与代码目录相关,测试阶段与测试目录相关。 If I commit some changes of tests in branch having an merge-request event i expect run test stage only, but pipeline calculates changes relative target branch and it will be changes of tests, and as the code too.如果我在具有合并请求事件的分支中提交了一些测试更改,我希望只运行测试阶段,但管道会计算相对于目标分支的更改,这将是测试的更改,也是代码的更改。 As result pipeline run all stages, include application build too, not only tests.结果管道运行所有阶段,包括应用程序构建,而不仅仅是测试。

Is the way to solve this problem: calculate the changes like in branch push - from previous commit, instead of target branch?解决这个问题的方法是:计算分支推送中的变化 - 从以前的提交,而不是目标分支? An example below, i expect: If no merge request: each commit into catalog "app/src" raise app building only.下面是一个示例,我希望:如果没有合并请求:每次提交到目录“app/src”只会引发应用程序构建。 Also if some test may be placed in other catalogs and it will not raise any built or tests.此外,如果某些测试可能被放置在其他目录中并且它不会引发任何构建或测试。 If merge request present: each commit into catalog "app/src" raise app building and run tests.如果存在合并请求:每次提交到目录“app/src”都会引发应用程序构建和运行测试。 Also, if some test changed outside catalog "app/src" it will raise tests only.此外,如果某些测试在目录“app/src”之外更改,它只会引发测试。

Stages:
    - build
    - test
build_job:
    stage: build
    script: 
        - echo App building
    only: 
        changes: 
        - app/src/**/* 
        variables:
        - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^dev\/.*/ && $CI_PIPELINE_SOURCE == 'merge_request_event'
        - $CI_OPEN_MERGE_REQUESTS == null && $CI_PIPELINE_SOURCE == 'push'
        - $CI_PIPELINE_SOURCE == 'web'
        - $CI_PIPELINE_SOURCE == 'api'

tests_job:
    stage: test
    script: 
        - echo App testing
    only: 
        variables:
        - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^dev\/.*/ && $CI_PIPELINE_SOURCE == 'merge_request_event'

In GitLab 15.3 you can used rules:changes with rules:changes:compare_to to compare a branch.在 GitLab 15.3 中,您可以使用rules:changesrules:changes:compare_to来比较一个分支。

in your case:在你的情况下:

build_job:
  stage: build
  script: 
    - echo App building
  rules: 
    changes:
      paths:
        - app/src/**/*
      compare_to: 'main'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅在 master 上启用合并请求管道 - enable merge request pipeline only on master 使用 Bash 和 cURL 通过 CI/CD 管道进入时生成 GitLab 合并请求 - Generate GitLab Merge Request when a push comes in via CI/CD Pipeline using Bash and cURL 在 gitlab ci MR 管道上运行所有作业,即使有些没有 merge_request_event 规则,但不要同时运行 MR 和分支管道 - Run all jobs on a gitlab ci MR pipeline, even if some don't have a merge_request_event rule, but do not run both MR and branch pipelines 为什么 Gitlab 在您批准合并请求时会自动将目标分支合并到源分支? 如何禁用此行为? - Why Gitlab automatically merge target branch into source branch when you approve a merge request? How to disable this behaviour? 将更改从 master 合并到我的分支的脚本 - Script that will merge changes from the master to my branch 如何使用 git 将 URL 获取到我当前分支的合并请求或拉取请求? - How can I get the URL to a merge request or a pull request of my current branch using git? Gitlab CI 根据合并请求自动运行管道 - Gitlab CI automatical run pipeline on merge request 如何在任何分支上的每次新推送时触发 Azure 管道? - How to trigger Azure Pipeline on every new push on any branch? GitLab 的唯一:更改和分支中的第一次提交 - GitLab's only:changes and the first commiit in a branch 使用 AWS copilot 创建了一个管道,原始推送有效但是当我更改代码并将它们推送到 github 时它们没有显示 - Created a pipeline using AWS copilot, original push worked but when I make changes to code and push them to github they don't show up
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM