Bash to deploy GitLab Pages in a branch like gh-pages
(Highly inspired from https://github.com/marketplace/actions/gh-pages-deploy)
It allows to keep track of modifications between to publications
- This creates a branch named "gh-pages"
- This stores the content of your branch "public/" directory inside
- On GitLab, you can choose to publish the "gh-pages" branch instead of the public artifacts using this in the ".gitlab-ci.yml":
pages: stage: deploy script: - echo "deploy" artifacts: paths: - public only: - gh-pages
Also think about using
except: gh-pages in your other stages because no file is available for this branch.
Create your token to allow push
Create New project token
Add token in the CI/CD variables as
Publish one site for each branch
If you use the environment variable :
variables: SITE_BY_BRANCH: "TRUE"
The 'gh-pages' branch will keep site content of other published branches in a dedicated subdirectory.
This will then create an index file at the root of your website to let you choose which version you want to see.
<h2>Index of branch directories</h2> - index.html - master - production - validation - other-branch