Can I pass artifacts across job from different projects- referring to commit SHA (needs:project keyword)?

Hello,
I am trying to use needs:project specifying a commit SHA in ref field. In following way:

job:
  stage: tests
  script:
    - ls
  needs:
    - project: namespace/myproject
      job: build
      ref: c443c50cee692309518ff624599e3dd2ce367293
      artifacts: true

Unfortunately I receive an error:
obraz

A similar job definition using tag and branch name in ref field, works fine for me. Also, I am sure that pipeline/job/artifacts exist for SHA that I’m trying to refer.

I wonder if commit SHA as ref for needs:project is supported or maybe I’m doing something wrong?

Unfortunately, I can not find information in documentation. However, similar context for ref field is used for include:project and documentation has a example with commit SHA as ref value. I wonder if behavior for needs:project suppose to be similar.

include:
  - project: 'my-group/my-project'
    ref: main                                      # Git branch
    file: '/templates/.gitlab-ci-template.yml'
  - project: 'my-group/my-project'
    ref: v1.0.0                                    # Git Tag
    file: '/templates/.gitlab-ci-template.yml'
  - project: 'my-group/my-project'
    ref: 787123b47f14b552955ca2786bc9542ae66fee5b  # Git SHA
    file: '/templates/.gitlab-ci-template.yml'

We are using self-hosted gitlab v15.8.4-ee. Gitlab runner: 15.2.1

Thank you,
P

1 Like

Have you found any solution or alternative to this?

No,it looks like the api doesn’t support it either. There is a request that allow you to download a artifacts from job (lnik below), but description for ref_name says:

Branch or tag name in repository. HEAD or SHA references are not supported.

Thus, only workaround that comes to my mind, is to create a artificial branch or tag, for commit from which you are willing to get artifacts.

1 Like

Yeah, those two were the only available options.

However, just now I happened to find this The artifacts are not found in the pipeline if they are created in the merge request pipeline (#267532) · Issues · GitLab.org / GitLab · GitLab

Basically, my requirement was to use MR (not SHA). And for that you have to pass this refs/merge-requests/1/head instead of just merge-requests/1. (I knew it should start with refs/ but didn’t know about passing head at the end.)

And this is working!!!