Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab-CI job fail when having a dependency on a previous manual job

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.

like image 802
cid Avatar asked Mar 09 '17 08:03

cid


2 Answers

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.

like image 101
Jakub Kania Avatar answered Oct 23 '22 09:10

Jakub Kania


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.

like image 1
cid Avatar answered Oct 23 '22 08:10

cid