【问题标题】:GitLab pass variable from one pipeline to anotherGitLab 将变量从一个管道传递到另一个管道
【发布时间】:2020-05-03 05:47:50
【问题描述】:

我们有一个主管道,负责从多个项目触发管道并执行一些步骤。我想将文件从第一个管道输出传递到第二个,但我无法这样做。

image:
  name: some-image
  entrypoint: [""]

variables:

stages:
  - create_file
  - print_file
  - consume_file

create_file:
  stage: create_file
  variables:
  trigger:
    project: user-name/project-name
    strategy: depend


print_file:
  stage: print_file
  script:
    - sleep 5
    - cat output_file.txt
  dependencies:
    - create_file

consume_file:
  stage: consume_file
  variables:
  trigger:
    project: user-name/project-name-alternate
    strategy: depend

我不想求助于脚本而不是触发器。已经尝试过工件等,但我找不到将它们传递到下一个管道的方法。

附:这只是管道中的一个示例,有多个管道依赖于第一个管道的输出。

【问题讨论】:

  • 基于official documents job artifacts 是传递文件和目录的好方法,而不是变量。建议你阅读官方文档中Passing variables to a downstream pipeline的文档。我希望这会有所帮助。
  • 同意,但目前无法使用trigger 传递工件。它们只能与脚本一起使用。

标签: variables gitlab gitlab-ci pipeline artifact


【解决方案1】:

由于工件可以在阶段之间传递,您可以尝试将变量写入 JSON 等文件,然后在另一个作业中对其进行解析。

【讨论】:

    【解决方案2】:

    将工件从下游管道传递到上游管道可能会根据此问题稍后实现:https://gitlab.com/gitlab-org/gitlab/-/issues/285100

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 2020-12-10
    • 2018-05-02
    • 2022-07-29
    • 1970-01-01
    • 2020-07-30
    相关资源
    最近更新 更多