英文:
How run a particular stage in GitLab after the execution of child pipelines'?
问题
以下是您要翻译的内容:
我正在使用GitLab,CI配置具有以下阶段:-
stages:
- test
- child_pipeline1
- child_pipeline2
- promote-test-reports
随时,只有一个子流程将运行,即在测试阶段之后运行child_pipeline1或child_pipeline2之一,而不是同时运行两者。
现在,我已经添加了一个名为promote-test-reports的另一个阶段,我希望在任何子流程成功执行后运行,即在子流程中的任何一个成功执行后运行。
但是我完全被阻止了。这个promote-test-reports来自一个我包含在这个主CI配置文件中的模板,如下所示:-
# 包含模板文件
include:
- project: arcesium/internal/vteams/commons/commons-helper
ref: promote-child-artifacts
file: 'templates/promote-child-artifacts.yml';
我在同一主文件中覆盖了GitLab项目令牌,如下所示:-
test:
stage: promote-test-reports
trigger:
include: adapter/child_pipelin1.yml
strategy: depend
variables:
GITLAB_PRIVATE_TOKEN: $GITLAB_TOKEN
如果您看到主CI配置文件中的上述阶段定义,我试图使用**strategy: depend**来等待child_pipeline1的成功执行,然后运行此阶段,但它会抛出错误(**jobs:test config contains unknown keys: trigger**),并且这种方法不起作用的原因是我在模板中的这个阶段(`promote-test-reports`)的主定义中使用了脚本,并根据文档,脚本和策略不能同时使用。
以下是模板中此阶段的定义:-
test:
stage: promote-test-reports
image: "495283289134.dkr.ecr.us-east-1.amazonaws.com/core/my-linux:centos7"
before_script:
- "yum install unzip -y"
variables:
GITLAB_PRIVATE_TOKEN: $GITLAB_TOKEN
allow_failure: true
script:
- 'cd $CI_PROJECT_DIR'
- 'echo running'
when: always
rules:
- if: $CI_PIPELINE_SOURCE == 'web'
artifacts:
reports:
junit: "**/testresult.xml"
coverage_report:
coverage_format: cobertura
path: "**/**/coverage.xml"
coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
使用`strategy`属性的想法失败了。我也不能删除模板中的脚本逻辑。我是否可以知道运行我的工作(`promote-test-reports`)的替代方法,记住它将是一个**OR**条件,要么在`child_pipeline1`之后运行,要么在`child_pipeline2`之后运行。
我非常感谢您的帮助。
英文:
I'm using GitLab and the CI config has got following stages:-
stages:
- test
- child_pipeline1
- child_pipeline2
- promote-test-reports
At any time, only one of the child pipeline will run i.e. either child_pipeline1 or child_pipeline2 after the test stage and not both at a time.
Now, I have added another stage called promote-test-reports which I would like to run in the end i.e. after the successful execution of any of child pipeline.
But I'm completely blocked here. This promote-test-reports is coming from a template which I have included in this main CI config file like:-
# Include the template file
include:
- project: arcesium/internal/vteams/commons/commons-helper
ref: promote-child-artifacts
file: 'templates/promote-child-artifacts.yml'
I'm overriding the GitLab project token in this same main file like below:-
test:
stage: promote-test-reports
trigger:
include: adapter/child_pipelin1.yml
strategy: depend
variables:
GITLAB_PRIVATE_TOKEN: $GITLAB_TOKEN
If you see the above stage definition in main CI config file, I'm trying to use strategy: depend to wait for successful execution of child_pipeline1 and then run this stage but it throwing error (jobs:test config contains unknown keys: trigger)and this approach is not working reason is I'm using scripts in the main definition of this stage (promote-test-reports
) in the template and as per the documentation both scripts and strategy cannot go together.
Following is the definition of this stage in the template:-
test:
stage: promote-test-reports
image: "495283289134.dkr.ecr.us-east-1.amazonaws.com/core/my-linux:centos7"
before_script:
- "yum install unzip -y"
variables:
GITLAB_PRIVATE_TOKEN: $GITLAB_TOKEN
allow_failure: true
script:
- 'cd $CI_PROJECT_DIR'
- 'echo running'
when: always
rules:
- if: $CI_PIPELINE_SOURCE == 'web'
artifacts:
reports:
junit: "**/testresult.xml"
coverage_report:
coverage_format: cobertura
path: "**/**/coverage.xml"
coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
The idea of using strategy
attribute failed. I cannot remove the logic of scripts in the template as well. May I know what is the alternate way of running my job(promote-test-reports
) in the end and remember it is going to be an OR condition that run either after child_pipeline1
or child_pipeline2
I would really appreciate your help
答案1
得分: 0
终于,我通过在子管道上添加strategy: depend
来完成了它。我之前在阶段promote-test-reports
上操作是错误的。
英文:
Finally, I was able to do it by putting the strategy: depend
on child pipelines. I was doing it incorrectly earlier by doing on stage, promote-test-reports
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论