6

Situation

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 

Result

The result of this pipeline on the master branch is:

gitlab-ci-result

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 

Conclusion

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.

Question

How can I implement this behaviour correctly? Namely, having a manual job which get triggered when an automatic job has dependencies on him?

Context

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.

Solution

In addendum to the accepted answer, see my own answer below.

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi @Jakub, Is it possible to use a stage name instead of the job name to make a job dependent on another job? That is, instead of using "build-doc" can I by any chance use "build"? Thanks.
@VibhavChaddha I'm not sure what you're asking and how it is connected to this question. But a job that is in next stage will proceed only if previous stage finishes so I think you don't have to change anything.
Sorry for that but I have also asked it as a separate question. I hope that might help you understand it better. Thanks. stackoverflow.com/questions/69278440/…
2

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.