Skip to content

needs: pipeline does not work for cross-project pipelines

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

Artifact downloads to child pipelines with needs when child pipeline is a pipeline in another project doesn't work without an additional ref to point to parent's ref name.

Steps to reproduce

Use Artifact downloads to child pipelines documentation to download artifact from a parent pipeline in a different project.

Parent CI file:

Prepare:Dotenv:
  stage: make-artifacts
  script:
    - echo "TEST_VARIABLE=test_${CI_PIPELINE_ID}" > test_${CI_PIPELINE_ID}.env
  artifacts:
    reports:
      dotenv: "test_${CI_PIPELINE_ID}.env"
    expire_in: 2 day

Trigger:Downstream:
  stage: trigger-downstream
  trigger:
    project: gitlab-gold/kategrechishkinatestgroup/213870-parent-child-artifact-download-issue-2
    branch: master
    strategy: depend
  needs:
    - job: Prepare:Dotenv
      artifacts: true
  variables:
    UPSTREAM_PROJECT_PIPELINE_ID: $CI_PIPELINE_ID
    UPSTREAM_PROJECT_DOTENVS_JOB: Prepare:Dotenv

Child CI file:

DirectlyTriggered:
  stage: use-artifacts
  script:
    - echo "$TEST_VARIABLE" # should work for bash, zsh, PowerShell
  needs:
    - pipeline: $UPSTREAM_PROJECT_PIPELINE_ID
      job: $UPSTREAM_PROJECT_DOTENVS_JOB
      artifacts: true

The child pipeline will fail with the error:

This job depends on other jobs with expired/erased artifacts: Please refer to https://docs.gitlab.com/ee/ci/yaml/README.html#dependencies

Example Project

What is the current bug behavior?

The child pipeline will fail

What is the expected correct behavior?

The child pipeline should succeed

Relevant logs and/or screenshots

Output of checks

This bug happens on GitLab.com

Workaround

  1. Pass CI_COMMIT_REF_NAME to the downstream pipeline as UPSTREAM_CI_COMMIT_REF_NAME and modify the needs:pipeline to needs:project statement in downstream pipeline and include it in ref::
  needs:
    - project: $UPSTREAM_PROJECT_PATH
      ref: $UPSTREAM_PROJECT_BRANCH
      job: $UPSTREAM_PROJECT_ARTIFACTS_JOB
      artifacts: true

This workaround, however, has a downside when you have multiple upstream pipelines started, the artifact from the most recent pipeline on that ref will be downloaded. It can lead to unexpected results in pipelines.

  1. Another workaround can be use API for downloading artifacts from the upstream.

Customer Report

This was reported by customer in internal ticket

Edited by 🤖 GitLab Bot 🤖