在gitlab-ci.yml管道中,我只能正确使用关键字?
这就是我的项目的结构看起来像
├── main_project
│ ├── service1
│ │ ├── [...]
│ ├── service2
│ │ ├── [...]
│ ├── docs
│ │ ├── [...]
│ ├── .gitlab-ci.yml
└── Makefile
我的.gitlab.ci-yml,
[...]
service1_build:
image: image
stage: build
script:
- #doing something
only:
changes:
- /service1/**/*
- /.gitlab-ci.yml
- /Makefile
except:
changes:
- /docs/**/*
service2_build:
image: image
stage: build
script:
- #doing something
only:
changes:
- /service2/**/*
- /.gitlab-ci.yml
- /Makefile
except:
changes:
- /docs/**/*
test:
image: image
stage: test
needs:
- service1_build
- service2_build
script:
- #doing something
except:
changes:
- /docs/**/*
service1_docker:
image: image
stage: docker
needs:
- test
script:
- #doing something
only:
refs:
- master
changes:
- /service1/**/*
- /.gitlab-ci.yml
- /Makefile
except:
changes:
- /docs/**/*
service2_docker:
image: image
stage: docker
needs:
- test
script:
- #doing something
only:
refs:
- master
changes:
- /service2/**/*
- /.gitlab-ci.yml
- /Makefile
except:
changes:
- /docs/**/*
[...]
但我尝试过,但它无法正常工作。例如,如果我更改docs
文件夹中的文件,则管道将执行test
作业。
这些是我要应用于每个作业的规则:
- service1_build :在所有分支上运行,当
service> service> service1
文件夹中有任何修改时,或者如果makefile
或.gitlab-ci.yml
已更改。但是,在修改了docs
文件夹中的文件时,它不应运行。 - service2_build :在所有分支上运行,当
service2
文件夹中进行任何修改时已更改。但是,在修改了docs
文件夹中的文件时,它不应运行。 - test :每次都在所有分支上运行,除非
docs中的文件
文件夹已修改。 - service1_docker :仅在
Master
上运行时,当service1
文件夹中有任何修改时,或者如果makefile
或<代码> .gitlab-ci.yml 已更改。但是,在修改了docs
文件夹中的文件时,它不应运行。 - service2_docker :仅在
Master
上运行时,当service2
文件夹中有任何修改时> .gitlab-ci.yml 已更改。但是,当文档中的文件
文件夹已修改时,它不应运行。
这是这样适用的吗?还是我应该如何处理?当我提供路径时,它总是从gitlab-ci.yml的
文件夹中查看它?
This is how my project's structure looks like
├── main_project
│ ├── service1
│ │ ├── [...]
│ ├── service2
│ │ ├── [...]
│ ├── docs
│ │ ├── [...]
│ ├── .gitlab-ci.yml
└── Makefile
My .gitlab.ci-yml
[...]
service1_build:
image: image
stage: build
script:
- #doing something
only:
changes:
- /service1/**/*
- /.gitlab-ci.yml
- /Makefile
except:
changes:
- /docs/**/*
service2_build:
image: image
stage: build
script:
- #doing something
only:
changes:
- /service2/**/*
- /.gitlab-ci.yml
- /Makefile
except:
changes:
- /docs/**/*
test:
image: image
stage: test
needs:
- service1_build
- service2_build
script:
- #doing something
except:
changes:
- /docs/**/*
service1_docker:
image: image
stage: docker
needs:
- test
script:
- #doing something
only:
refs:
- master
changes:
- /service1/**/*
- /.gitlab-ci.yml
- /Makefile
except:
changes:
- /docs/**/*
service2_docker:
image: image
stage: docker
needs:
- test
script:
- #doing something
only:
refs:
- master
changes:
- /service2/**/*
- /.gitlab-ci.yml
- /Makefile
except:
changes:
- /docs/**/*
[...]
I tried this, but it is not working properly. For example, if I change a file in docs
folder, the test
job will be executed by the pipeline.
These are the rules that I want to be applied to each job:
- service1_build: run on all branches, when there is any modification within the
service1
folder or ifMakefile
or.gitlab-ci.yml
has been changed. But it should not run when files indocs
folder have been modified. - service2_build: run on all branches, when there is any modification within the
service2
folder or ifMakefile
or.gitlab-ci.yml
has been changed. But it should not run when files indocs
folder have been modified. - test: run on all branches every time, except when files in
docs
folder have been modified. - service1_docker: run only on
master
, when there is any modification within theservice1
folder or ifMakefile
or.gitlab-ci.yml
has been changed. But it should not run when files indocs
folder have been modified. - service2_docker: run only on
master
, when there is any modification within theservice2
folder or ifMakefile
or.gitlab-ci.yml
has been changed. But it should not run when files indocs
folder have been modified.
Is this applicable like this? Or how should I handle this? When I am giving the path, it always looking it from the gitlab-ci.yml's
folder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
遵循项目结构,您应该尝试更改唯一的/除了这样的路径以外:
这包括
main_project
目录。您还应该为您的测试工作添加一些可选的需求,因为如果Service1上只有更新,测试作业将转移到Service2作业并失败:
我对这些新修复程序进行了一些测试,您的规则正常工作: https://gitlab.com/sandbox_fm/ci-rules 。
您还应该考虑从/仅/除了规则因为:
Following your project structure, you should try to change your only/except paths like this :
This include the
main_project
directory.You should also add some optional needs to your test job, because if there is only updates on service1, the test job will look to the service2 job and fail :
I made some tests with these new fix and your rules are working properly : https://gitlab.com/sandbox_fm/ci-rules.
You also should consider moving from only/except to rules because :