hugo/content/hosting-and-deployment/hosting-on-gitlab.md
Bjørn Erik Pedersen ed8bf081fd Squashed 'docs/' changes from 3068989b9..d9c8fc220
d9c8fc220 Rebuild Chroma CSS
a9168b106 Adds missing word
ebaa172af Remove note about enabling custom GitLab domains
2ef3918b2 Add code toggler
41878b6ca Clarify the use of .GetPage with page bundles
ffcb26270 Fix broken link for configuration.md
1e72e2b3e Fixed typo in heading - Hightlighter
72b2db77c Change "on the form" to "of the form"
e15e6966f Fix example GitHub url

git-subtree-dir: docs
git-subtree-split: d9c8fc220710fe2bdcc2c61afd9e40e7233953cf
2018-04-02 08:53:34 +02:00

2.6 KiB

title linktitle description date publishdate lastmod categories keywords authors menu weight sections_weight draft toc wip aliases
Host on GitLab Host on GitLab 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. 2016-06-23 2016-06-23 2017-11-16
hosting and deployment
hosting
deployment
git
gitlab
Riku-Pekka Silvola
docs
parent weight
hosting-and-deployment 40
40 40 false true false
/tutorials/hosting-on-gitlab/

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, as well as numerous other static site generators.

Assumptions

  • Working familiarity with Git for version control
  • Completion of the Hugo Quick Start
  • A GitLab account
  • 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>/.

Next Steps

GitLab supports using custom CNAME's and TLS certificates. For more details on GitLab Pages, see the GitLab Pages setup documentation.