Automate Hugo Deployment with Gitlab CI/CD
Having my personal gitlab instance I decided to automate hugo deployment process using gitlabci and each time a new commit is merged to master branch, the site will rebuild using ‘hugo’ command and will be deployed to my server (webhosting provider in my case) using lftp.
In my example ‘gitlab-ci.yaml’ configuration there are 2 stages (test-only & Deploy-Pages)
If I’m pushing to a working branch will trigger the pipeline on each commit and will run only the test stage.
If I will merge my changes to master or commit to master directly the pipeline will run the Deploy-Pages stage.
SFTP_SERVER, FTP_USER and FTP_PASSWORD are configured as Variables in Settings -> CI/CD -> Variables section.
I always have my local/repo public folder empty to avoid pollution from old files, public folder contents will be generated during build having always actual/valid content and in sync with the remote server.