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
The first thing to test about blog posts that came to mind were the links they contained as they might be broken.
Add a build task to check for broken links
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:
npmtask that would install
broken-link-checkerwith the following settings:
Command and arguments:
install broken-link-checker -g
Command Linetask 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.