Can I use GitLab Pages on self-hosted instance?
Yes, GitLab Pages works on self-hosted instances. You may need to register a wildcard domain name for *.pages.<your-gitlab-domain-name>
, and generate SSL certs if you are running gitlab over https only.
Once you have a domain, edit /etc/gitlab/gitlab.rb
and add the extra settings, and run a gitlab-ctl reconfigure
(leave out the pages_nginx
settings if you are running over http only):
gitlab_pages['enable'] = true
pages_external_url "https://pages.<your-gitlab-domain-name>"
pages_nginx['redirect_http_to_https'] = true
pages_nginx['ssl_certificate'] = "/etc/gitlab/ssl/pages.<your-gitlab-domain-name>.crt"
pages_nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/pages.<your-gitlab-domain-name>.key"
Once that is done you will be able to access per-project pages via <group>.pages.<your-gitlab-domain-name>/<project>
Can I upload whatever I want to pages?
Yes. Each GitLab CI job can create content to publish in GitLab pages by writing it into a public
folder, and registering public
as an artifact directory. A final pages
job should be added to the CI pipeline which causes the pages content to be published (overwriting anything that was there before). All the content of the public
directory will be available via the <group>.pages.<your-gitlab-domain-name>/<project>
URL, which means you have full control over content.
Note that the pages job in CI doesn't need to have any script, it just needs to be present with the job name "pages". This is a magic job name that triggers the pages publish. You may want to add job restrictions so that this only runs on master branch pipelines.
Can I add pages publish to an existing project?
Yes. Any steps that create content you want to publish should write the content to a public
subdirectory, and register the public
directory as an artifact directory.
my job:
stage: build
script:
- echo "Do some things and write them to public directory" > public/index.html
artifacts:
paths:
- public
expire_in: 2 weeks
Note: I like to add expire_in: 2 weeks
to limit the length of time artifacts are kept around. Once the pages have been published the artifacts aren't really needed.
Finally you need to add a pages
job to trigger the pages publish:
# This job does nothing but collect artifacts from other jobs and triggers the pages build
# The artifacts are picked up by the pages:deploy job.
pages:
stage: deploy
script:
- ls -l public
artifacts:
paths:
- public
only:
- master
Usually you will only want to publish on master branch, but you have freedom to choose when you want the pages publish to run. It is important to note that when the pages publish runs it will fully replace any content that was previously published, so you can't append to existing content (although there are some hacks that allow you to achieve something similar).