Unclear artifacts behaviour when "needs"-keyword is used

Hi,

I would like to use artifacts to exchange data between jobs. In my example I have 4 jobs on 3 stages.
I see, that folder “dir2” that is created and added to the artifacts in “job_2” is visible only in “job_3”, but is missing from “job_4”. The file foo.txt created in “job_1” is not available in “job_3”.

If I don’t use the “needs”-keyword everything works as expected.

Why is the behaviour different with “needs”? Do I need to specify all jobs whose artifacts I want gitlab to download?

I’m using

  • GitLab (Hint: /help): 13.8
  • Runner (Hint: /admin/runners): kubernetes executor?

My .gitlab.yml

stages:

  • stage_1
  • stage_2
  • stage_3

job_1:
stage: stage_1
tags:
- kubernetes
image: ${DOCKER_IMAGE}

script:
- mkdir -p dir1
- cd dir1
- echo “foo” >> foo.txt
- cd -
artifacts:
paths:
- dir1
expire_in: 1 hour

job_2:
stage: stage_1
tags:
- kubernetes
image: ${DOCKER_IMAGE}

script:
- mkdir -p dir1
- cd dir1
- echo “test1” >> test1.txt
- cd -
- mkdir -p dir2
- cd dir2
- echo “test2” >> test2.txt
- cd -
artifacts:
paths:
- dir1
- dir2
expire_in: 1 hour

job_3:
stage: stage_2
tags:
- kubernetes
image: ${DOCKER_IMAGE}

needs: [“job_2”]
script:
- ls
- cd dir1
- ls
- echo “test1” >> test1a.txt
- cd -
- cd dir2
- ls
- cd -
- mkdir -p dir3
- cd dir3
- echo “test3” >> test3.txt
- cd -
artifacts:
paths:
- dir1
- dir3
expire_in: 1 hour

job_4:
stage: stage_3
tags:
- kubernetes
image: ${DOCKER_IMAGE}
needs: [“job_3”]
script:
- ls
- cd dir1
- ls
- cd -

Thanks,
oz