I want to define dependencies to share artifacts from one hidden job to another, so that when I extend a hidden job/use it in a pipeline, I don't need to specify that the job depends on another hidden job's artifacts, e.g.:
.foo:
script:
- mkdir test/
- echo "hello-world" > test/foobar.txt
artifacts:
paths:
- test/
.bar:
script:
- do something
needs:
- job: .foo
dependencies:
- .foo
artifacts:
paths:
- test/
foo-call:
extends: .foo
stage: first_stage
baz:
extends: .bar
stage: first_stage
# I should have access to the artifacts produced in foo-call
But I haven't had great luck in getting this to work in any capacity, and I largely suspect that any implementation of this would be inorganic.
Are there any obvious options I am missing here?
Unfortunately, you can't declare hidden jobs as targets of dependencies:
-- you can only specify concrete (not hidden) jobs that actually exist in the pipeline. This means that you often can't reasonably/meaningfully create hidden job templates that declare dependencies:
in advance -- the dependencies will need to be declared with the concrete jobs. The same goes for needs:
.
One alternative would be to require the concrete jobs to be in different ordered stages. Then depedenceis:
can be left blank and artifacts to download will be implied by the stage ordering.
Additionally, needs:
implies dependencies:
so you only have to define needs:
in this case.
So remove needs:
/dependencies:
from the hidden jobs:
.foo:
script:
- mkdir test/
- echo "hello-world" > test/foobar.txt
artifacts:
paths:
- test/
.bar:
script:
- do something
artifacts:
paths:
- test/
And declare needs:
for the actual jobs:
foo-call:
extends: .foo
stage: first_stage
baz:
extends: .bar
stage: first_stage
needs: [foo-call]
Or use different stages without needs:
/dependencies:
:
foo-call:
extends: .foo
stage: first_stage
baz:
extends: .bar
stage: second_stage