Skip to content

Instantly share code, notes, and snippets.

@kaystrobach
Created July 29, 2022 08:13
Show Gist options
  • Save kaystrobach/4f8fc239dc0b77d4161a41aa83acb493 to your computer and use it in GitHub Desktop.
Save kaystrobach/4f8fc239dc0b77d4161a41aa83acb493 to your computer and use it in GitHub Desktop.
title author layout date categories url
Using hugo with gitlab CI including review apps in gitlab pages
Kay Strobach
post
2022-07-29 10:56:01 +0000
Nützliches
WebDev
Gitlab
hugo
/post/2022/07/29/hugo.html

I was asked on twitter wether hugo can be used with a ci tool to automatically upload the result via ftp.

And yes it's possible, this is basically, what I'm doing in this blog.

stages:
  - build
  - deploy



runHugoMaster:
  stage: build
  image: publysher/hugo:latest
  script:
    - git submodule init
    - git submodule update
    - hugo check
    - hugo --baseURL=$DOMAIN
  artifacts:
    paths:
      - public/*
    expire_in: 1 week
  cache:
    untracked: true
    paths:
      - public
  tags:
    - docker
  only:
    - master
    - main
  environment:
    name: production
    url: $DOMAIN

runHugoReview:
  stage: build
  image: jojomi/hugo:0.38
  script:
    - git submodule init
    - git submodule update
    - hugo check
    - hugo --baseURL=$DOMAIN/builds/$CI_BUILD_REF_NAME
  artifacts:
    paths:
      - public/*
    expire_in: 1 week
  cache:
    untracked: true
    paths:
      - public
  tags:
    - docker
  except:
    - master
  environment:
    name: review/$CI_BUILD_REF_NAME
    url: https://blog.kay-strobach.de/builds/$CI_BUILD_REF_NAME
    on_stop: stop_review

uploadResult:
  stage: deploy
  image: dockito/lftp-client
  script:
    - lftp -e "set dns:order inet; set sftp:auto-confirm yes; set ssl:verify-certificate no; set net:connection-limit 3; mirror --exclude ^\.git.* --exclude ^Resources/Private/ --exclude \.gitlab-ci.yaml -eRv  public builds/$CI_BUILD_REF_NAME; quit;" ftp://$CREDENTIALS
  artifacts:
    paths:
      - public/*
  tags:
    - docker

stop_review:
  stage: deploy
  variables:
    GIT_STRATEGY: none
  image: dockito/lftp-client
  script:
    - lftp  -e "set dns:order inet; set sftp:auto-confirm yes; set ssl:verify-certificate no; set net:connection-limit 3; rm -r builds/$CI_BUILD_REF_NAME; quit;" ftp://$CREDENTIALS
  when: manual
  except:
    - master
  environment:
    name: review/$CI_BUILD_REF_NAME
    action: stop
  tags:
    - docker

This pipeline consists of 4 jobs:

  • runHugoMaster - builds the hugo artifacts for the main / default branch
  • runHugoReview - does the same, but for the review apps
  • uploadResult - uploads the resulting code to the publication server
  • stop_review - deletes the preview
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment