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

Website content

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

I wonder if the following is still valid and reliable. I found it on a blog post written in 2016.

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

Is the current CI template any better?

pages:
  stage: deploy
  environment: production
  script:
    - mkdir .public
    - cp -r ./* .public
    - rm -rf public
    - mv .public public
  artifacts:
    paths:
      - public
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

Hey there,

I believe both should work just as fine :slight_smile: The current template has just two modifications (not mandatory, but a “nice-to-have”):

  • environment: production - this specifies production environment. Basically this means that the deployment will be visible in your project on Deployments > Environments page.
  • rules vs only - if your $CI_DEFAULT_BRANCH is main then this will work identically. Those two lines (in both configs) just say when to run the job (on which branch), and the rules one is a bit more generic and will work for more broad projects (in case someone for their project has e.g. master branch instead of main)

Hope this helps!

1 Like