hugo/content/en/hosting-and-deployment/hosting-on-gitlab.md
Bjørn Erik Pedersen cb39847dee Squashed 'docs/' changes from a26d0e610..7297c1172
7297c1172 Add note about caching for Hugo Pipes.
c91be3403 minor markdown, capitalization and spelling fixes (#1183)
fd4a103bf Fix several 404 errors (#1162)
69378bc20 Update related.md
28c24e95f Add note on setting baseURL
7b1502c99 minor typo fix (#1180)
33abeb4fe Update related.md
4887563f6 Update js.md
ee5f1de2e Hugo 0.74.3
986ea0c8e releaser: Add release notes to /docs for release of 0.74.3
3299b44bd Fix Asciidoctor args
bcb950347 resources/js: Add option for setting bundle format
3f8324918 resources/js: Add es5 build target

git-subtree-dir: docs
git-subtree-split: 7297c1172754078511ac1c10ca0dfd4cab629506
2020-08-14 18:31:01 +02:00

88 lines
2.9 KiB
Markdown

---
title: Host on GitLab
linktitle: Host on GitLab
description: GitLab makes it incredibly 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/]
---
[GitLab](https://gitlab.com/) makes it incredibly easy to build, deploy, and host your Hugo website via their free GitLab Pages service, which provides [native support for Hugo, as well as numerous other static site generators](https://gitlab.com/pages/hugo).
## 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
## Create .gitlab-ci.yml
```
cd your-hugo-site
```
In the root directory of your Hugo site, create a `.gitlab-ci.yml` file. The `.gitlab-ci.yml` configures the GitLab CI on how to build your page. Simply add the content below.
{{< code file=".gitlab-ci.yml" >}}
image: monachus/hugo
variables:
GIT_SUBMODULE_STRATEGY: recursive
pages:
script:
- hugo
artifacts:
paths:
- public
only:
- master
{{< /code >}}
## 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.
```
# 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>/`.
{{% note %}}
Make sure your `baseURL` key-value in your [site configuration](/getting-started/configuration/) reflects the full URL of your GitLab pages repository if you're using the default GitLab Pages URL (e.g., `https://<YourUsername>.gitlab.io/<your-hugo-site>/`) and not a custom domain.
{{% /note %}}
## 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/