4

We have a master pipeline, which is responsible for triggering pipelines from multiple projects and performing some steps. I want to pass a file from first pipelines output to the second one but i am unable to do so.

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

I don't want to resort to scripts instead of trigger. Have tried artifacts etc but i couldn't find a way to pass them on to the next pipelines.

P.s. this is just a sample set out of the pipelines, there are multiple pipelines that are dependent on the output from first pipeline.

  • Base on [official documents](https://docs.gitlab.com/ee/user/project/pipelines/job_artifacts.html) job **artifacts** is a good way for passing files and directories, not variables. I suggest you read documents of [Passing variables to a downstream pipeline](https://docs.gitlab.com/ee/ci/multi_project_pipelines.html#passing-variables-to-a-downstream-pipeline) in official documents. I hope this helps. – Amir Dadkhah Jan 16 '20 at 19:58
  • Yes agreed, but artifacts cannot be passed with a `trigger` at the moment. They can only be used with scripts. – ahmedwaleedmalik Jan 17 '20 at 06:12

3 Answers3

1

See if GitLab 14.10 (April 2022) can help:

Improved pipeline variables inheritance

Previously, it was possible to pass some CI/CD variables to a downstream pipeline through a trigger job, but variables added in manual pipeline runs or by using the API could not be forwarded.

In this release we’ve added a new trigger:forward keyword to control what things you forward to downstream parent-child pipelines or multi-project pipelines, which provides a flexible way to handle variable inheritance in downstream pipelines.

See Documentation and Issue.

Note that, on self-managed GitLab, by default this feature is not available.
To make it available, ask an administrator to enable the feature flag named ci_trigger_forward_variables. The feature is not (yet) ready for production use (in Apr. 2022).

Example of trigger:forward:

Run this pipeline manually, with the CI/CD variable MYVAR = my value:

variables: # default variables for each job
  VAR: value

# Default behavior:
# - VAR is passed to the child
# - MYVAR is not passed to the child
child1:
  trigger:
    include: .child-pipeline.yml

# Forward pipeline variables:
# - VAR is passed to the child
# - MYVAR is passed to the child
child2:
  trigger:
    include: .child-pipeline.yml
    forward:
      pipeline_variables: true

# Do not forward YAML variables:
# - VAR is not passed to the child
# - MYVAR is not passed to the child
child3:
  trigger:
    include: .child-pipeline.yml
    forward:
      yaml_variables: false
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • And is it possible to pass variables (or artifacts) from downstream to upstream ? – Ecora May 02 '22 at 11:39
  • @ThezozolinoL Not sure, since this is about upstream to downstream. – VonC May 02 '22 at 11:40
  • So how will I be able to get values from a child pipeline ? Exemple: My CHILD pipeline create a staging environment with dynamic URL. How to retrieve this URL in my PARENT pipeline, if i want execute tests on this url ? – Ecora May 02 '22 at 12:06
  • 1
    @ThezozolinoL Not sure again. Regarding artifact, this is to be in backlog: https://gitlab.com/gitlab-org/gitlab/-/issues/285100 – VonC May 02 '22 at 12:52
0

Since artifacts can be passed between stages, you can try writing the variables into a file such as JSON, and parse it in another job.

Edmund Wang
  • 109
  • 1
  • 2
0

Passing artifacts from downstream pipelines to upstream ones may be implemented later according to this issue: https://gitlab.com/gitlab-org/gitlab/-/issues/285100

Lost Lont
  • 51
  • 1
  • 4
  • Personally I'm not fond of the idea though, as it sounds contradictory to the purpose of a _downstream_ object. If scripts as an option was discarded not because of it's functionality but for example because the file would be too long then I'd resort to including the script from a separate file via the `include` keyword. – Lost Lont Dec 09 '21 at 17:10
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30548692) – MD. RAKIB HASAN Dec 14 '21 at 08:44