5

I want to download an Artifact in a job present in a Child pipeline from another job present in another Child pipeline part of the same parent-child pipeline hierarchy.

I tried with the files below that are inspired from the Gitlab documentation (see the paragraph "Example of needs:pipeline:job" in https://docs.gitlab.com/ee/ci/yaml/) but with no success (I have this error : This job depends on other jobs with expired/erased artifacts)

parent.yml

parent1:
  stage: test
  trigger:
    include: child1.yml
    strategy: depend

parent2:
  stage: test
  trigger:
    include: child2.yml
    strategy: depend
  variables:
    PARENT_PIPELINE_ID: $CI_PIPELINE_ID

Child1.yml

create-artifact:
  stage: build
  script: echo "sample artifact" > artifact.txt
  artifacts:
    paths: [artifact.txt]

Child2.yml

use-artifact:
  script: cat artifact.txt
  needs:
    - pipeline: $PARENT_PIPELINE_ID
      job: create-artifact

So according to the official Gitlab documentation : A child pipeline can download artifacts from a job in its parent pipeline or another child pipeline in the same parent-child pipeline hierarchy. so I am wondering how to make it work in my example files?

6
  • Hi, it is not possible yet. See the issue gitlab.com/gitlab-org/gitlab/-/issues/285100
    – borievka
    Commented Jun 2, 2022 at 15:41
  • Hello. You are trying to use it on the different parent-child pipeline hierarchy. Look into the documentation that you are mention - "in the same parent-child pipeline hierarchy" Commented Oct 2, 2022 at 19:32
  • I hear its possible by using commit-ref in your cache, then grabbing it from the cache
    – blamb
    Commented Nov 17, 2022 at 0:37
  • @blamb do you have and example of that that you could post as an anwser?
    – St. Jan
    Commented Jul 18, 2023 at 13:14
  • 1
    sorry I dont, id have to look it up again. I will check my browser history for it though. I think i found it on a gitlab bug report page.
    – blamb
    Commented Jul 18, 2023 at 15:37

1 Answer 1

0

To grab artifacts from a job in another child pipeline within the same parent-child pipeline hierarchy, you can use the needs keyword along with the pipeline and job attributes. Here's how you can tweak your setup: parent.yml:

parent1:
  stage: test
  trigger:
    include: child1.yml
    strategy: depend

parent2:
  stage: test
  trigger:
    include: child2.yml
    strategy: depend
  variables:
    PARENT_PIPELINE_ID: $CI_PIPELINE_ID
child1.yml:
create-artifact:
  stage: build
  script: echo "sample artifact" > artifact.txt
  artifacts:
    paths: [artifact.txt]
    expire_in: 1 hour
child2.yml:
use-artifact:
  stage: test
  script: cat artifact.txt
  needs:
    - project: $CI_PROJECT_PATH
      job: create-artifact
      ref: $CI_COMMIT_REF_NAME
      artifacts: true

Here's what's going on: 1. In child1.yml, the create-artifact job creates an artifact and sets an expiration time of 1 hour using expire_in. This way, the artifact is available for a short period.

2.  In child2.yml, the use-artifact job uses needs to specify that it depends on the create-artifact job from another child pipeline.
▪   project tells GitLab where to find the job. It uses $CI_PROJECT_PATH to point to the current project.
▪   job specifies the name of the job that creates the artifact.
▪   ref tells GitLab which branch or tag to look for. It uses $CI_COMMIT_REF_NAME to refer to the current branch or tag.
▪   artifacts is set to true to let GitLab know that the job needs the artifacts from the specified job.

By using needs with these attributes, the use-artifact job in child2.yml can download and use the artifact created by the create-artifact job in child1.yml. Just keep in mind that the create-artifact job needs to finish successfully and the artifact should be available within the expiration time set by expire_in. Also, make sure the parent pipeline triggers both child pipelines and passes the necessary variables (PARENT_PIPELINE_ID) to set up the parent-child pipeline hierarchy correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.