meller92
meller92

Reputation: 455

GitLab Pages, docs generated with sphinx

I want to host static page generated with Sphinx on GitLab Pages. Built index.html file is in:

project/docs/build/html

How .gitlab-ci.yml should look like to deploy the page? I have something like that and it isn't working:

pages:
  stage: deploy
  script:
  - echo 'Nothing to do...'
 artifacts:
 paths:
 - docs/build/html
 only:
 - master

Upvotes: 19

Views: 19660

Answers (2)

kerfuffle
kerfuffle

Reputation: 314

image: python:3.10-alpine

stages:
  - deploy

pages:
  tags:
    - sphinx
  stage: deploy
  script:
    - python3 -m pip install sphinx furo
    - sphinx-build -b html docs/source/ public/
  artifacts:
    paths:
      - public
  only:
    - main # 'master' was renamed to 'main' 

This is what my GitLab-ci.yml looks like. On a side note: You don't need a public-folder in your repository. GitLab itself will handle it. I installed furo as theme (make sure to change the conf.py accordingly) to make it look nicer.

Upvotes: 1

systemexit
systemexit

Reputation: 590

According to the documentation for .gitlab-ci.yml, the pages job has special rules it must follow:

  1. Any static content must be placed under a public/ directory
  2. artifacts with a path to the public/ directory must be defined

So the example .gitlab-ci.yml you gave would look something like this:

pages:
  stage: deploy
  script:
    - mv docs/build/html/ public/
  artifacts:
    paths:
    - public
  only:
  - master

And of course, if you don't want to move the html folder for whatever reason, you can copy it instead.

For further reference, an example sphinx project for GitLab Pages was pushed around the time you originally posted this question.

Upvotes: 20

Related Questions