【问题标题】:GitLab: Job artifacts in multi project pipelinesGitLab:多项目管道中的作业工件
【发布时间】:2020-08-18 02:09:39
【问题描述】:

我已经尝试学习多项目管道有一段时间了,除了 GitLab 文档,我还没有找到任何学习资料。如果我能看到一个例子,那真的很有帮助。我一直在为项目 A 中的多项目管道使用以下 ci 配置,但它不起作用:

trigger_job:
  stage: trigger_release  
  trigger:
    project: https://<gitlab-site>/api/v4/projects/<project-B-id>/trigger/pipeline
    branch: master
    strategy: depend

这会使项目 A 中的管道永远处于挂起状态。我以以下方式使用 curl 最终使配置正常工作:

trigger_job:
  stage: trigger_release 
  script:
    - curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=master https://<gitlab-site>/api/v4/projects/<project-B-id>/trigger/pipeline

但是,我真正需要的是在触发的作业完成后,在项目 A 管道中收集和使用项目 B 管道的工件。我该怎么做?

【问题讨论】:

  • 你看到这个needs关键字usage了吗?
  • 那会怎样?我自己使用了 needs 关键字来指定工作是否需要以前工作的工件,或者是否需要在以前的工作中取得成功才能连续工作。但它如何让我访问从触发管道到触发管道的作业工件?

标签: gitlab gitlab-ci pipeline gitlab-api


【解决方案1】:

从 Gitlab 11.8 开始。你不需要使用 API 来触发管道,see official documentation

例子

让我们将mygroup 与 2 个 repos 组合在一起:myrepository1myrepository2

repository1中的配置

trigger-job:
  trigger:
    project: mygroup/myrepository2
    branch: master
  variables:
    VARIABLE_TO_PASS: $CI_COMMIT_REF_NAME

repository2中的配置

job-waiting-for-trigger:
  stage: deploy
  variables:
  script:
    - echo "${VARIABLE_TO_PASS} from another project pipeline"
  only:
    - pipelines

这段代码我没试过,但应该是正确的。

【讨论】:

    猜你喜欢
    • 2022-01-19
    • 2021-06-25
    • 2021-03-27
    • 2022-06-11
    • 2018-03-17
    • 1970-01-01
    • 2022-01-22
    • 2021-04-10
    • 2022-01-19
    相关资源
    最近更新 更多