Gitlab CI and Pages

Gitlab CI and Gitlab Pages allow you to deploy automatically your static assets on a Gitlab server.

This is how this blog runs :)

So each project you create on Gitlab can have its own pages, deployed depending rules you set in the Continuous Integration file, the .gitlab-ci.yml.

What you can do with Gitlab pages and gitlab-ci:

  • build and test your application on each commit
  • assure that every merge on master won’t break the build
  • deploy a static website on a custom fqdn when building a branch

What you cannot do:

  • review apps, a feature that allow you to deploy feature branches for review, are not supported yet for gitlab pages. If you want to review your static website, you will need to get your own server (I recommend 3$/month servers). But we will only see here what you can do without a credit card.

Let’s go

Create a new gitlab repository. Make it private or public, as you want.

Next you need to have some static content. I chose H.U.G.O. but it can be anything, even static html files.

So let’s imagine you have committed a index.html at the root of your gitlab project, and you want to publish that.

    <h1>Hello Pages World!</h1>

You would only have to add the .gitlab-ci.yml file, describing a pages job that contain an artifact targeting the public directory.

  stage: deploy
  - master
  - echo deploying pages
  - mkdir public
  - cp index.html public/
    - public

Gitlab will detect the name of the job, pages, and will automatically deploy the content of the publicdirectory.

If you go to your pipeline, you will see that a stage appeared:


And if you go to Settings -> Pages in your repository, you will see a message saying that your pages are deployed :


Just follow the link!

Next step : You can easily configure your pages to be on you custom fqdn. See the Gitlab Pages Documentation

comments powered by Disqus