github.com/jbramsden/hugo@v0.47.1/docs/content/en/hosting-and-deployment/hosting-on-gitlab.md (about)

     1  ---
     2  title: Host on GitLab
     3  linktitle: Host on GitLab
     4  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.
     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  [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).
    24  
    25  ## Assumptions
    26  
    27  * Working familiarity with Git for version control
    28  * Completion of the Hugo [Quick Start][]
    29  * A [GitLab account](https://gitlab.com/users/sign_in)
    30  * A Hugo website on your local machine that you are ready to publish
    31  
    32  ## Create .gitlab-ci.yml
    33  
    34  ```
    35  cd your-hugo-site
    36  ```
    37  
    38  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.
    39  
    40  {{< code file="gitlab-ci.yml" >}}
    41  image: monachus/hugo
    42  
    43  variables:
    44    GIT_SUBMODULE_STRATEGY: recursive
    45  
    46  pages:
    47    script:
    48    - hugo
    49    artifacts:
    50      paths:
    51      - public
    52    only:
    53    - master
    54  {{< /code >}}
    55  
    56  ## Push Your Hugo Website to GitLab
    57  
    58  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.
    59  
    60  ```
    61  # initialize new git repository
    62  git init
    63  
    64  # add /public directory to our .gitignore file
    65  echo "/public" >> .gitignore
    66  
    67  # commit and push code to master branch
    68  git add .
    69  git commit -m "Initial commit"
    70  git remote add origin https://gitlab.com/YourUsername/your-hugo-site.git
    71  git push -u origin master
    72  ```
    73  
    74  ## Wait for Your Page to Build
    75  
    76  That's it! You can now follow the CI agent building your page at `https://gitlab.com/<YourUsername>/<your-hugo-site>/pipelines`.
    77  
    78  After the build has passed, your new website is available at `https://<YourUsername>.gitlab.io/<your-hugo-site>/`.
    79  
    80  ## Next Steps
    81  
    82  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/).
    83  
    84  [Quick Start]: /getting-started/quick-start/