Search code examples
gitlabgitlab-cipipeline

Deploy gitlab pages using downstream stage


This is my folder tree:

proj/
 ├─ src/
 ├─ docs/
 │  ├─ public/
 │  │  ├─ assets/
 │  │  ├─ index.html
 │  ├─ .gitlab-ci.yml
 ├─ config/
 ├─ .gitlab-ci.yml

As you can see there are two .gitlab-ci.yml files. The first, in the root of the project is the master pipeline that trigger the second one into the docs folder. I would like that the first pipeline in addition to deploy the application (only on a specific branch) trigger the second pipeline and deploy the documentation on giltab pages.

This is the code of the docs/.gitlab-ci.yml:

image: alpine:latest

pages:
  stage: deploy
  script:
  - echo 'Nothing to do...'
  artifacts:
    paths:
    - public/
    expire_in: 1 day

And this is is the .gitlab-ci.yml in the project's root:

stages:
  - deploy-docs
  - gen-text
  - deploy-in-dev

gen-text:
  stage: gen-text
  image: python:3.10.0
  before_script:
    - pip3 install -r ./command/requirements.txt
  script:
    - python3 ./command/main.py
  artifacts:
    paths:
      - src/languages
    expire_in: 1 day
  only: ['stg']

deploy-in-dev:
  stage: deploy-in-dev
  image: node:latest
  dependencies:
    - gen-text
  script:
    - echo 'Only stg with artifacts'
  only: ['stg']

docs:
  stage: deploy-docs
  trigger:
    include: docs/.gitlab-ci.yml

The pipeline trigger correctly the downstream but it's fail: missing pages artifacts. So, how can I pass the public folder to the downstream and why the secondary .gitlab-ci.yml doesn't see the folder?


Solution

  • The issue seems to be with the path that you provided for the artifacts in downstream

    paths:
    - public/
    

    You should change it to

    paths:
    - docs/public/
    

    When you include the child pipeline the current working directory doesn't change, it still is in proj/ and not in docs/