'Downloading a package from Gitlab package registry

I have a gitlab-ci.yml file that creates a maven deployment and am trying to trigger another pipeline that takes the package from the registry and create a docker image

image: maven:latest

before_script:
  - mvn --version

stages:
  - build
  - trigger

build:
  stage: build
  script:
    - mvn package
    - mvn deploy 
  artifacts:
    paths:
      - target/*

trigger:
  stage: trigger
  trigger:
    project: my/other/project/repo
    branch: master

I'm having trouble finding out just how to get that package (or published artifacts) to the triggered pipeline. When using the container registry I just specify the image and gitlab pulls it down, not sure if I'm missing something obvious here but how do I actually use/download a package from gitlab?

I've tried to curl files in the package registry like this

curl --header "PRIVATE-TOKEN: my_token" "https://gitlab.com/api/v4/projects/00112233/packages/generic/io/my/package/0.0.1-SNAPSHOT/myfile.xml"

which throws the following error

{"error":"package_version is invalid"}

But when I curl GET on the package that is the package version

[
  {
    "id": 123456,
    "name": "io/my/package",
    "version": "0.0.1-SNAPSHOT",
    "package_type": "maven",
    "status": "default",
    "_links": {
      "web_path": "/my/web/path/-/packages/00112233",
      "delete_api_path": "https://gitlab.com/api/v4/projects/0123456/packages/00112233"
    },
    "created_at": "2022-01-11T23:59:28.626Z",
    "tags": [
      
    ]
  }
]

Is it possible to use or download the packages in gitlab in another pipeline triggered?

Additional code:

.gitlab-ci.yml

image: maven:latest

before_script:
  - mvn --version

variables:
  PARENT_JOB_ID: myteststring # This works
  # PARENT_JOB_ID: $CI_JOB_ID # This doesn't

stages:
  - build
  - trigger

build:
  stage: build
  script:
    - mvn package
    - mvn deploy 

trigger:
  stage: trigger
  trigger:
    include: my_ci.yml

my_ci.yml

image:
  name: docker:20

services:
  - docker:dind

stages:
  - test

test:
  stage: test
  script:
    - echo $JOB_ID # echos nothing if $CI_JOB_ID is $PARENT_JOB_ID, echos the string if it's something else

========================

Output from job when PARENT_JOB_ID is set to a random string

Executing "step_script" stage of the job script
00:00
Using docker image sha256:15a9bc7c6340df2ac9d6c8196ca1d905180ddf2ca8b29a8d98f5422e2e5ccf85 for docker:20 with digest docker@sha256:a729cce205a05b0b86dc8dca87823efaffc3f74979fe7dc86a707c2fbf631b61 ...
$ echo "Test string = $PARENT_JOB_ID"
Test string = myteststring

Output from job when PARENT_JOB_ID is set to CI_JOB_ID

Executing "step_script" stage of the job script
00:00
Using docker image sha256:15a9bc7c6340df2ac9d6c8196ca1d905180ddf2ca8b29a8d98f5422e2e5ccf85 for docker:20 with digest docker@sha256:a729cce205a05b0b86dc8dca87823efaffc3f74979fe7dc86a707c2fbf631b61 ...
$ echo "Test string = $PARENT_JOB_ID"
Test string =


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source