Most tutorials about Hugo and GitHub Pages assume everything lives on GitHub and use GitHub Actions. My setup is a bit different:

  • the sources of the blog (Markdown, theme, config) live in a private Azure Repos repository;
  • the generated site is served by GitHub Pages, for free;
  • Azure Pipelines builds the site with Hugo and pushes the result to GitHub.

As a bonus, a daily run publishes posts that are written in advance: a post dated next Monday shows up on Monday, without touching anything.

Here is the whole setup, and the traps I fell into.

How it works

  1. I push a new post to the master branch of the Azure Repos repository.
  2. Azure Pipelines starts, installs Hugo and builds the site into public/.
  3. The pipeline copies public/ into the GitHub Pages repository and pushes it.
  4. GitHub Pages serves the new version a minute later.

On top of that, the pipeline also runs every day at a fixed time, so posts with a date in the future are published on their day.

What you need

  • A Hugo site in an Azure Repos repository (here the theme is a git submodule in themes/).
  • A GitHub Pages repository, for example <github-user>/<github-user>.github.io, served from its master branch.
  • An Azure DevOps project where you can create pipelines.

A token that can only do one thing

The pipeline needs to push to the GitHub Pages repository. Don't use your password or a classic token with access to everything: create a fine-grained personal access token, in GitHub Settings → Developer settings → Personal access tokens → Fine-grained tokens:

  • Repository access: Only select repositories → the GitHub Pages repository only.
  • Permissions: Contents → Read and write. Nothing else.

Then store it in the pipeline: Edit → Variables → New variable, name it GITHUB_PAT, paste the token and tick Keep this value secret. A secret variable is masked in the logs and is not passed to scripts unless you map it explicitly (see the last step below).

Warning

Fine-grained tokens expire. Put a reminder in your calendar a few days before the end date: when the token expires, the build still succeeds but publishing fails.

The pipeline

Create azure-pipelines.yml at the root of the repository:

trigger:
  branches:
    include: [ master ]

# Daily build: posts dated today get published even without a new commit
schedules:
- cron: '0 10 * * *'        # always UTC
  displayName: Daily publish
  branches:
    include: [ master ]
  always: true              # run even if nothing changed in the repository

pool:
  vmImage: ubuntu-latest

variables:
  HUGO_VERSION: '0.169.0'
  PAGES_REPO: 'github.com/<github-user>/<github-user>.github.io.git'
  PAGES_BRANCH: 'master'

steps:
- checkout: self
  fetchDepth: 0
  submodules: true          # the theme is a git submodule

- script: |
    set -e
    wget -q https://github.com/gohugoio/hugo/releases/download/v$(HUGO_VERSION)/hugo_extended_$(HUGO_VERSION)_linux-amd64.tar.gz
    tar -xzf hugo_extended_$(HUGO_VERSION)_linux-amd64.tar.gz hugo
    sudo mv hugo /usr/local/bin/
    hugo version
  displayName: Install Hugo

- script: hugo --minify --cleanDestinationDir
  displayName: Build site

- script: |
    set -e
    git clone --depth 1 --branch $(PAGES_BRANCH) https://x-access-token:${GITHUB_PAT}@$(PAGES_REPO) pages
    find pages -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
    cp -r public/. pages/
    touch pages/.nojekyll
    cd pages
    git config user.name "Azure Pipelines"
    git config user.email "azure-pipelines@users.noreply.github.com"
    git add -A
    if git diff --cached --quiet; then
      echo "No change to publish"
    else
      git commit -m "Publish $(Build.SourceVersion)"
      git push origin $(PAGES_BRANCH)
    fi
  displayName: Publish to GitHub Pages
  env:
    GITHUB_PAT: $(GITHUB_PAT)

Then in Azure DevOps: Pipelines → New pipeline → Azure Repos Git → your repository → Existing Azure Pipelines YAML file → /azure-pipelines.yml.

Step by step

Checkout. submodules: true fetches the theme, fetchDepth: 0 fetches the full history (useful if you ever enable Hugo's Git info for "last modified" dates).

Install Hugo. The version is pinned in a variable. Use the same version as on your machine, and take the extended build: most themes need it for SCSS. When you update Hugo locally, update this line too.

Build. --minify makes the HTML and CSS smaller, --cleanDestinationDir removes files of pages that no longer exist.

Publish. Instead of force-pushing a fresh repository every time, the step clones the GitHub Pages repository, replaces its content with the new site and commits only if something changed. The history of the published site stays readable, and the daily runs where nothing changed create no empty commit. .nojekyll tells GitHub Pages to serve the files as they are, without running Jekyll on them.

Note

The token reaches the script only because of the env: block at the end. Without it, ${GITHUB_PAT} is empty: secret variables are never exposed to scripts automatically.

Scheduled posts

This part needs no plugin: it's Hugo's default behaviour. A page whose date is in the future is not built (unless you run Hugo with --buildFuture). So:

---
title: "My next post"
date: 2026-12-01
draft: false
---

This post is pushed today, but it stays invisible until the first build on December 1st. That's the job of the schedules block: with always: true, the pipeline runs every day even when the repository didn't change, and Hugo picks up the posts whose day has come.

Tip

To preview a scheduled post on your machine, run hugo server --buildFuture.

Two details about the cron:

  • It is always in UTC. 0 10 * * * is 11:00 in Central Europe in winter and 12:00 in summer. There is no time zone option, so pick the hour that suits you best for both seasons, or use two schedules limited to their months.
  • After a push, check Pipelines → your pipeline → ⋮ → Scheduled runs: the next planned runs should be listed there.

The traps I fell into

fetch-depth is GitHub Actions syntax. My first run failed with Unexpected value 'fetch-depth'. In Azure Pipelines the checkout option is camelCase: fetchDepth.

The theme folder was empty. With the theme as a git submodule, the checkout doesn't fetch it unless you add submodules: true. Hugo then builds pages without any layout.

"Scheduled runs" was nowhere to be found. That menu only exists for YAML pipelines. And if a schedule was ever defined in the pipeline settings (Edit → ⋮ → Triggers), it overrides the one in the YAML: leave that tab empty.

The custom domain disappeared after a deployment. GitHub Pages stores the custom domain in a CNAME file at the root of the published repository. Since the pipeline replaces all the files, put CNAME in Hugo's static/ folder: it's copied into public/ at every build.

www.example.com

An old classic pipeline was still active. If you move from a classic (designer) pipeline to YAML, disable the old one, otherwise both run on each push.

When to use GitHub Actions instead

If your sources can live on GitHub, GitHub Actions is simpler: Pages can be deployed directly from a workflow, without a token or a second repository. This Azure Pipelines setup makes sense when you want the sources to stay private in Azure DevOps while keeping the free hosting of GitHub Pages, or when your other projects already run on Azure DevOps.