Answers: <p>To grab artifacts from a job in another child pipeline within the same parent-child pipeline hierarchy, you can use the <code>needs</code> keyword along with the <code>pipeline</code> and <code>job</code> attributes. Here's how you can tweak your setup:
  parent.yml:</p>
  <pre class="lang-yaml prettyprint-override"><code>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 &quot;sample artifact&quot; &gt; 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
  </code></pre>
  <p>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.</p>
  <pre><code>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.
  </code></pre>
  <p>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.</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-04-26T11:12:01.113Z
Answers: 2024-04-26T11:12:01.113Z
Answers: Thomas Vincent
Body: <p>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.</p>
  <p>I tried with the files below that are inspired from the Gitlab documentation (see the paragraph &quot;Example of needs:pipeline:job&quot; in <a href="https://docs.gitlab.com/ee/ci/yaml/" rel="nofollow noreferrer">https://docs.gitlab.com/ee/ci/yaml/</a>) but <strong>with no success</strong> (I have this error : <em>This job depends on other jobs with expired/erased artifacts</em>)</p>
  <p>parent.yml</p>
  <pre><code>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
  </code></pre>
  <p>Child1.yml</p>
  <pre><code>create-artifact:
    stage: build
    script: echo &quot;sample artifact&quot; &gt; artifact.txt
    artifacts:
      paths: [artifact.txt]
  </code></pre>
  <p>Child2.yml</p>
  <pre><code>use-artifact:
    script: cat artifact.txt
    needs:
      - pipeline: $PARENT_PIPELINE_ID
        job: create-artifact
  </code></pre>
  <p>So according to the official Gitlab documentation : <em>A child pipeline can download artifacts from a job in its parent pipeline or another child pipeline in the same parent-child pipeline hierarchy.</em> so I am wondering how to make it work in my example files?</p>
  
Comments: CC BY-SA 4.0
Comments: 2022-06-02T15:41:20.993Z
Comments: Hi, it is not possible yet. See the issue https://gitlab.com/gitlab-org/gitlab/-/issues/285100
Comments: borievka
Comments: CC BY-SA 4.0
Comments: 2022-10-02T19:32:40.123Z
Comments: 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"
Comments: Serhiy Nazarov
Comments: CC BY-SA 4.0
Comments: 2022-11-17T00:37:30.233Z
Comments: I hear its possible by using commit-ref in your cache, then grabbing it from the cache
Comments: blamb
Comments: CC BY-SA 4.0
Comments: 2023-07-18T13:14:32.007Z
Comments: @blamb do you have and example of that that you could post as an anwser?
Comments: St. Jan
Comments: CC BY-SA 4.0
Comments: 2023-07-18T15:37:13.420Z
Comments: 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.
Comments: blamb
Comments: CC BY-SA 4.0
Comments: 2023-07-18T21:27:10.390Z
Comments: would be great, I have been reading and reading...still no solution
Comments: St. Jan
Tags: <gitlab><pipeline>
Title: Gitlab : Download artifacts from a job in another child pipeline
UserDisplayName: AmineDg
ThreadText: # Gitlab : Download artifacts from a job in another child pipeline
  
  (Asked by: username_0 on 2022-04-10)
  
  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?
  
  **Tags:** gitlab, pipeline
  
  > **Comments:**
  > **username_1**: Hi, it is not possible yet. See the issue https://gitlab.com/gitlab-org/gitlab/-/issues/285100  
  > **username_2**: 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"  
  > **username_3**: I hear its possible by using commit-ref in your cache, then grabbing it from the cache  
  > **username_4**: @username_3 do you have and example of that that you could post as an anwser?  
  > **username_3**: 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.  
  > **username_4**: would be great, I have been reading and reading...still no solution  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_5 on 2024-04-26. Score: 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:
  
  ```yaml
  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.
  
  
  ---
  
  