[英]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:changes
和rules: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.