Consider the following .gitlab-ci.yml
example:
build:
stage: build
script: echo "Building..."
build-doc:
stage: build
when: manual
script:
- echo "Building doc..."
- echo "build result" > output.txt
artifacts:
name: "%CI_BUILD_NAME%_%CI_BUILD_ID%"
expire_in: 1 week
paths:
- "output.txt"
deploy-doc:
stage: deploy
only:
- master
dependencies:
- build-doc
script:
- echo "Deploying doc..."
- type output.txt
The result of this pipeline on the master
branch is:
The log of the deploy-doc
job says:
$ echo "Deploying doc..."
"Deploying doc..."
$ type output.txt
The system cannot find the file specified.
ERROR: Build failed: exit status 1
Even if the deploy-doc
has explicitly a dependency on the manual build-doc
job artifact, the build-doc
don't get triggered leading to the a fail of the deploy-doc
job.
How can I implement this behaviour correctly? Namely, having a manual job which get triggered when an automatic job has dependencies on him?
I only want to automatically build and deploy the doc on the master
branch, the other branches can only build the doc manually to download the generated doc.
In addendum to the accepted answer, see my own answer below.
The easiest way will be to use a trigger. Define the deploy-doc
job as:
only:
- triggers
Use yaml anchors to do two copies of build-doc
one declared as
only:
- master
the other one as
when:
- manual
Have the build-doc
call the trigger when it ends. This will rebuild the whole pipeline so you could define build
job as
except:
- triggers
Or use $CI_JOB_MANUAL
variable and have deploy-doc
run only on master and triggers so at least on master it won't rebuild everything.
Thanks to the Jackub Kania answer, which points me in the right direction, I ended up using yaml anchors to solve my problem.
I simply modified the actual build-doc
to a .build-doc-template
anchor job (just removed the manual
condition) and created two version of the build-doc
job as following:
build-doc:
<<: *build-doc-template
only:
- master
build-doc-manual:
<<: *build-doc-template
when: manual
except:
- master
This way, I could avoid the triggers complication. Ask for full code if needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With