2020-09-18 13:35:38 +00:00
+++
2018-11-22 16:49:29 +00:00
title = "GitLab Pages"
2020-07-22 16:40:43 +00:00
weight = 40
2018-11-22 16:49:29 +00:00
+++
We are going to use the GitLab CI runner to automatically publish the site (this CI runner is already included in your repository if you use GitLab.com).
## Repository setup
Your repository needs to be set up to be a user or group website. This means the name of the repository has to be in the correct format.
2019-11-26 19:30:30 +00:00
For example, assuming that the username is `john` , you have to create a project called `john.gitlab.io` . Your project URL will be `https://gitlab.com/john/john.gitlab.io` . Once you enable GitLab Pages for your project, your website will be published under `https://john.gitlab.io` .
2018-11-22 16:49:29 +00:00
Under your group `websites` , you created a project called `websites.gitlab.io` . Your project’ s URL will be `https://gitlab.com/websites/websites.gitlab.io` . Once you enable GitLab Pages for your project, your website will be published under `https://websites.gitlab.io` .
2020-09-04 20:53:31 +00:00
This guide assumes that your Zola project is located in the root of your repository.
2018-11-22 16:49:29 +00:00
## Ensuring that the CI runner can access your theme
2019-11-26 19:30:30 +00:00
Depending on how you added your theme, your repository may not contain it. The best way to ensure that the theme will
be added is to use submodules. When doing this, ensure that you are using the `https` version of the URL.
2018-11-22 16:49:29 +00:00
```shell
$ git submodule add {THEME_URL} themes/{THEME_NAME}
```
2019-11-26 19:30:30 +00:00
For example, this could look like:
2018-11-22 16:49:29 +00:00
```shell
$ git submodule add https://github.com/getzola/hyde.git themes/hyde
```
## Setting up the GitLab CI/CD Runner
2020-09-04 20:53:31 +00:00
The second step is to tell the GitLab continuous integration runner how to create the GitLab page.
2018-11-22 16:49:29 +00:00
2019-11-26 19:30:30 +00:00
To do this, create a file called `.gitlab-ci.yml` in the root directory of your repository.
2018-11-22 16:49:29 +00:00
```yaml
2020-09-18 13:35:38 +00:00
image: alpine:latest
2018-11-22 16:49:29 +00:00
variables:
# This variable will ensure that the CI runner pulls in your theme from the submodule
2021-02-03 12:13:49 +00:00
GIT_SUBMODULE_STRATEGY: recursive
2018-11-22 16:49:29 +00:00
pages:
script:
2020-12-06 20:43:23 +00:00
# Install the zola package from the alpine community repositories
2021-02-03 12:13:49 +00:00
- apk add --update-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ zola
2018-11-22 16:49:29 +00:00
# Execute zola build
2020-09-18 13:35:38 +00:00
- zola build
2021-02-03 12:13:49 +00:00
2018-11-22 16:49:29 +00:00
artifacts:
paths:
# Path of our artifacts
- public
2021-02-03 12:13:49 +00:00
2018-11-22 16:49:29 +00:00
# This config will only publish changes that are pushed on the master branch
2021-02-03 12:13:49 +00:00
only:
2020-09-18 13:35:38 +00:00
- master
2018-11-22 16:49:29 +00:00
```
2019-11-26 19:30:30 +00:00
Push this new file and ... Tada! You're done! If you navigate to `settings > pages` , you should be able to see
something like this:
2018-11-22 16:49:29 +00:00
> Congratulations! Your pages are served under:
https://john.gitlab.io
More information on the process to host on GitLab pages and additional information like using a custom domain is documented
[in this GitLab blog post ](https://about.gitlab.com/2016/04/07/gitlab-pages-setup/ ).