DEV Community

Dian
Dian

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

before_script:
  - hugo version

github_pages:
  script:
  - rm -rf public
  - git clone --depth 1 https://<username>:$GITHUB_ACCESS_TOKEN@github.com/<username>/<username>.github.io.git public
  - hugo --config config.production.toml
  - cd public
  - git config user.email "<your git email>"
  - git config --global user.name "<your git name>"
  - git add -A
  - git commit -m "Build from $CI_SERVER_NAME $CI_PIPELINE_ID"
  - git push
  artifacts:
    paths:
    - public
  only:
  - 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 https://github.com/settings/tokens.

And then...

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

Build Hugo from Gitlab CI

Awesome!

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)

Collapse
 
littledove22 profile image
Mary Luketich

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

Collapse
 
ardianta profile image
Dian

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: github.com/gohugoid/gohugoid-web (it's using Github Action)