I have the following .gitlab-ci.yml
configuration:
stages:
- stage1
- stage2
- stage3
job1:
stage: stage1
rules:
- if: $RUN != "job3"
when: always
- when: never
script:
- date > data/test1.txt
cache:
key: test-cache
paths:
- data/test1.txt
job2:
stage: stage2
rules:
- if: $RUN != "job3"
when: always
- when: never
script:
- date > test2.txt
cache:
key: test-cache
paths:
- test2.txt
job3:
stage: stage3
rules:
- if: $RUN == "job3"
script:
- cat data/test1.txt
- cat test2.txt
cache:
key: test-cache
paths:
- data/test1.txt
- test2.txt
The plan is to do the following:
- To run the pipeline with the variable
RUN
not defined, so that ONLY the two jobsjob1
andjob2
are run, but NOTjob3
. The two jobsjob1
andjob2
are supposed to add the filesdata/test1.txt
andtest2.txt
to the cache, so they can be fetched later byjob3
. - To run the pipeline with the variable
RUN
set torun3
, which ONLY runs the jobjob3
. This job is supposed to fetch the previously generated files from the cache, namely the two filesdata/test1.txt
andtest2.txt
.
Explanation:
In reality, the two jobs job1
and job2
are very time consuming jobs which also consume a lot of API calls. Therefore, I do not want to rerun them for no reason, as they would generate the same results anyway. I just want to “store” the results from these two jobs job1
and job2
, and “fetch” these results from a later running job (maybe a few days later). This job3
will also run in the same pipeline in the same repo and on the same branch. as the jobs job1
and job2
.
Expected result:
job3
can use the two files from the cache created by job1
and job2
.
Observed result:
$ cat data/test1.txt
cat: data/test1.txt: No such file or directory
I have the following questions:
- How can I fix this problem? What IS the problem?
- Where is this documented?