DEV Community


Posted on

Deploy Hugo from Gitlab CI to Github Pages

I have Hugo blog, hosted on Github Pages and using Travis CI to deploy it.
But at new year, Travis CI take long time to queue my build.

Travis CI

Travis CI Status: Container-based Linux over capacity

As alternatif, I use Gitlab CI and mirroring my blog repository from Github to Gitlab.

Here my .gitlab-ci.yml script:

image: andthensome/alpine-hugo-git-bash:0.31.2

  - hugo version

  - rm -rf public
  - git clone --depth 1 https://<username>:$<username>/<username> public
  - hugo --config config.production.toml
  - cd public
  - git config "<your git email>"
  - git config --global "<your git name>"
  - git add -A
  - git commit -m "Build from $CI_SERVER_NAME $CI_PIPELINE_ID"
  - git push
    - public
  - master
Enter fullscreen mode Exit fullscreen mode

We need to create environment variable GITHUB_ACCESS_TOKEN at Gitlab. Just go to Settings->CI/DI->Secret Variables.

Creating Secret Variable

You can get your Github Personal Token at

And then...

Lets try to build it by commiting some changes to master branch on Gitlab.

Build Hugo from Gitlab CI


Now my blog is deployed from Gitlab CI to Github Pages, hare what look like on Github Pages repository.

Github Pages Repository

(you also can read Indonesian version on my blog)

Top comments (2)

littledove22 profile image
Mary Luketich

Why are you using Gitlab? Why not just deploy from Github?

ardianta profile image

This post was made before Github add the Github Action feature. So, the way to deploy Hugo to Github pages is using external CI/DI like Travis and Gitlab CI. But now, we have CI/DI on Github, it called Github Action. I have try it, and it was awesome.

You can check the repo: (it's using Github Action)