mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
c1398b91a9
3f95a2ace Update merge function examples (#1662) e8d518011 requires -> require typo fix (#1666) e714066cb Update GitLab deployment instructions (#1661) 11946a218 update GitLab CI/CD yaml syntax (#1649) 3568ddc03 Add explicit `contentDir` to module-config-mounts (#1658) 798ac8f68 Add default value to isHTML d376565ce Create extensions.json git-subtree-dir: docs git-subtree-split: 3f95a2ace37b04851905d72e4444020e30996787
86 lines
2.7 KiB
Markdown
86 lines
2.7 KiB
Markdown
---
|
|
title: Host on GitLab
|
|
linktitle: Host on GitLab
|
|
description: GitLab makes it easy to build, deploy, and host your Hugo website via their free GitLab Pages service, which provides native support for Hugo.
|
|
date: 2016-06-23
|
|
publishdate: 2016-06-23
|
|
lastmod: 2017-11-16
|
|
categories: [hosting and deployment]
|
|
keywords: [hosting,deployment,git,gitlab]
|
|
authors: [Riku-Pekka Silvola]
|
|
menu:
|
|
docs:
|
|
parent: "hosting-and-deployment"
|
|
weight: 40
|
|
weight: 40
|
|
sections_weight: 40
|
|
draft: false
|
|
toc: true
|
|
wip: false
|
|
aliases: [/tutorials/hosting-on-gitlab/]
|
|
---
|
|
|
|
## Assumptions
|
|
|
|
* Working familiarity with Git for version control
|
|
* Completion of the Hugo [Quick Start]
|
|
* A [GitLab account](https://gitlab.com/users/sign_in)
|
|
* A Hugo website on your local machine that you are ready to publish
|
|
|
|
## BaseURL
|
|
|
|
The `baseURL` in your [site configuration](/getting-started/configuration/) must reflect the full URL of your GitLab pages repository if you are using the default GitLab Pages URL (e.g., `https://<YourUsername>.gitlab.io/<your-hugo-site>/`) and not a custom domain.
|
|
|
|
## Configure GitLab CI/CD
|
|
|
|
Define your [CI/CD](https://docs.gitlab.com/ee/ci/quick_start/) jobs by creating a `.gitlab-ci.yml` file in the root of your project.
|
|
|
|
{{< code file=".gitlab-ci.yml" >}}
|
|
image: registry.gitlab.com/pages/hugo/hugo_extended:latest
|
|
|
|
variables:
|
|
GIT_SUBMODULE_STRATEGY: recursive
|
|
|
|
pages:
|
|
script:
|
|
- hugo
|
|
artifacts:
|
|
paths:
|
|
- public
|
|
rules:
|
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
|
{{< /code >}}
|
|
|
|
{{% note %}}
|
|
See [this list](https://gitlab.com/pages/hugo/container_registry) if you wish to use a particular Hugo version to build your site.
|
|
{{% /note %}}
|
|
|
|
## Push Your Hugo Website to GitLab
|
|
|
|
Next, create a new repository on GitLab. It is *not* necessary to make the repository public. In addition, you might want to add `/public` to your .gitignore file, as there is no need to push compiled assets to GitLab or keep your output website in version control.
|
|
|
|
```bash
|
|
# initialize new git repository
|
|
git init
|
|
|
|
# add /public directory to our .gitignore file
|
|
echo "/public" >> .gitignore
|
|
|
|
# commit and push code to master branch
|
|
git add .
|
|
git commit -m "Initial commit"
|
|
git remote add origin https://gitlab.com/YourUsername/your-hugo-site.git
|
|
git push -u origin master
|
|
```
|
|
|
|
## Wait for Your Page to Build
|
|
|
|
That's it! You can now follow the CI agent building your page at `https://gitlab.com/<YourUsername>/<your-hugo-site>/pipelines`.
|
|
|
|
After the build has passed, your new website is available at `https://<YourUsername>.gitlab.io/<your-hugo-site>/`.
|
|
|
|
## Next Steps
|
|
|
|
GitLab supports using custom CNAME's and TLS certificates. For more details on GitLab Pages, see the [GitLab Pages setup documentation](https://about.gitlab.com/2016/04/07/gitlab-pages-setup/).
|
|
|
|
[Quick Start]: /getting-started/quick-start/
|