three gitlab-ci jobs - lets call them A, B and C.
they are all in the same stage (if that matters)
so clearly job C needs to depend on A and B to finish (artifacts are generated when they finish). But the docs don't seem to have such an entry. They only have a trigger for success and failure. not for finished jobs in general.
stages:
- build
- test
- coverage
build_job:
stage: build
script:
- echo building...
test_job_A:
needs:
- build_job
stage: test
script:
- echo "logs of tests executed in A" > test_result_A.txt
artifacts:
paths:
- test_result_*
test_job_B:
needs:
- build_job
stage: test
script:
- echo "logs of tests executed in B" > test_result_B.txt
- mimic failing pipeline
artifacts:
paths:
- test_result_*
coverage_C:
needs:
- test_job_A
- test_job_B
stage: test
script:
- cat test_result_A.txt
- cat test_result_B.txt
which will result in the coverage_C
job not executed:
using dependencies
and moving the job C into another stage:
...
coverage_C:
dependencies:
- test_job_A
- test_job_B
stage: coverage
script:
- cat test_result_A.txt
- cat test_result_B.txt
coverage_C
is in test
, shouldn't it be in coverage
? In any case, test_job_B
fails, therefore any job that depends on its success (!) will not start. That is a reasonable default interpretation of what a dependency means.
Your mistake is that by using the default, you depend on the success of the test jobs, you need to configure coverage_C
so that it runs even if one of its dependencies fails. Check out the docs for the jobs' rules section, you need when: always
.
Now, there is still another challenge left: A failing job will by default not export any artifacts. You probably want test logs even if one of them fails, so you will have to configure that as well. As a suggestion, create an empty file first though, so if anything fails fatally and the file is not created, it doesn't cause the dependent job to fail.
Allow me to edit your answer for some more details. You can re-write this as you like.
...
test_job_B:
needs:
- build_job
stage: test
script:
- echo "logs of tests executed in B" > test_result_B.txt
- mimic failing pipeline
artifacts:
when: always
paths:
- test_result_*
coverage_C:
needs:
- test_job_A
- test_job_B
stage: coverage
script:
- cat test_result_A.txt
- cat test_result_B.txt
when: always
other_job_D:
stage: test
script:
- sleep 200
Important for the failing job is the artifacts:when:always
to save the artifacts on failure.
the needs
is completely correct. Using dependencies
will end up waiting for the complete prior stage - which is unwanted.
the stage
should be a stage that is after the jobs you want to wait for. So in this case it would be stage: coverage
job C then also needs the when:always
flag because it doesn't want to depend on job success of jobs A and B