gitlabyamlgitlab-cigitlab-ci.ymlgitlab-pages

Minimal .gitlab-ci.yml file for deploying a plain HTML website


I have a static HTML website with the following structure:

.
├── index.html
└── images/
    ├── a.jpg
    ├── b.jpg
    └── c.jpg

I found the following configuration in a blog post from 2016:

pages:
  stage: deploy
  script:
  - mkdir .public
  - cp -r * .public
  - mv .public public
  artifacts:
    paths:
    - public
  only:
  - main

I attempted to simplify it to:

pages:
  stage: deploy
  script:
    - mkdir -p public
    - cp -r * public
  artifacts:
    paths:
      - public
  only:
    - main

Is this simplified version valid, functional, and reliable for deploying a plain HTML website with GitLab CI/CD? Will it remain robust and continue to correctly deploy the entire content, including any new files such as scripts, stylesheets, or additional HTML pages that I might add to the root directory in the future?


Solution

  • I don't see why the simplified version shouldn't work. To deploy to GitLab pages, you have to move files to the public folder and declare that folder as artifact. This has not changed, see the docs.

    However, only is now deprecated and you should use rules. E.g.:

    pages:
      # …
      rules:
        - if: $CI_COMMIT_BRANCH == "main"