The blog of Blog of Christian Bär

Testing this blog's content

This blog is built using hugo, a static site generator and a continuous integration/deployment process (CI/CD) is set up for automatic publication.
But wait! There’s hardly any CI and even less CD without automated tests, right? I certainly don’t want to end up in developer hell for not setting up some!

Run tests before publication

Before updates are published to this blog, some tests must be executed. There are different aspects that might be tested, the two main ones would be implementation (e.g. templates and JavaScript code) and the contents of the actual posts. This post is focusing on the latter.

The first thing to test about blog posts that came to mind were the links they contained as they might be broken.

I’ve already described how I put together some tasks in an Azure Pipelines build definition.

To check this blog for broken links I basically added some new task(s) to the build definition just before the task that would swap the working directory and the public blog directory. (Hence the new task would check the contents of the working directory.)

First approach: Use a Command Line Task

My first approach was to find some command line utility in the internet that I could install and call from a task of type Command Line. I found the npm package broken-link-checker which does just what I want.

Now I only needed to add two tasks:

  1. An npm task that would install broken-link-checker with the following settings:
    Command: custom
    Command and arguments: install broken-link-checker -g
  2. A Command Line task that would run broken-link-checker’s command line utility like:
    blc http://some.site.com -rog -exclude https://broken.anyways.net -exclude https://broken.also.com

Second approach: Create and use an Azure DevOps extension

After I had configured and run the first approach I thought it might be nice to make that functionality even easier to use and decided to create an Azure DevOps extension.

The extension can be installed from the Marketplace. Stay tuned for my next post about how I implemented the extension.

Share this post!