hosting-on-gitlab.md (2813B)
1 --- 2 title: Host on GitLab 3 linktitle: Host on GitLab 4 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. 5 date: 2016-06-23 6 publishdate: 2016-06-23 7 lastmod: 2017-11-16 8 categories: [hosting and deployment] 9 keywords: [hosting,deployment,git,gitlab] 10 authors: [Riku-Pekka Silvola] 11 menu: 12 docs: 13 parent: "hosting-and-deployment" 14 weight: 40 15 weight: 40 16 sections_weight: 40 17 draft: false 18 toc: true 19 wip: false 20 aliases: [/tutorials/hosting-on-gitlab/] 21 --- 22 23 ## Assumptions 24 25 * Working familiarity with Git for version control 26 * Completion of the Hugo [Quick Start] 27 * A [GitLab account](https://gitlab.com/users/sign_in) 28 * A Hugo website on your local machine that you are ready to publish 29 30 ## BaseURL 31 32 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. 33 34 ## Configure GitLab CI/CD 35 36 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. 37 38 {{< code file=".gitlab-ci.yml" >}} 39 image: registry.gitlab.com/pages/hugo/hugo_extended:latest 40 41 variables: 42 GIT_SUBMODULE_STRATEGY: recursive 43 44 pages: 45 script: 46 - hugo 47 artifacts: 48 paths: 49 - public 50 rules: 51 - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH 52 {{< /code >}} 53 54 {{% note %}} 55 See [this list](https://gitlab.com/pages/hugo/container_registry) if you wish to use a particular Hugo version to build your site. 56 {{% /note %}} 57 58 ## Push Your Hugo Website to GitLab 59 60 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. 61 62 ```bash 63 # initialize new git repository 64 git init 65 66 # add /public directory to our .gitignore file 67 echo "/public" >> .gitignore 68 69 # commit and push code to master branch 70 git add . 71 git commit -m "Initial commit" 72 git remote add origin https://gitlab.com/YourUsername/your-hugo-site.git 73 git push -u origin master 74 ``` 75 76 ## Wait for Your Page to Build 77 78 That's it! You can now follow the CI agent building your page at `https://gitlab.com/<YourUsername>/<your-hugo-site>/pipelines`. 79 80 After the build has passed, your new website is available at `https://<YourUsername>.gitlab.io/<your-hugo-site>/`. 81 82 ## Next Steps 83 84 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/). 85 86 [Quick Start]: /getting-started/quick-start/