Build and Publish a Wyam Static Site Using CI CD Pipeline

Published on Sunday, September 1, 2019

How to using a CI/CD Pipeline to automatically build and publish a static website using Wyam?

Note: We are going to use Azure DevOps CI/CD pipeline.

Prepare a static website using Wyam generator

If you have not a website that is generated by Wyam, please check this page or this page to create one.

Cake Build Tool

For implementing the automatically build in CI (Continous Integration) in a pipeline, the Wyam generated-site needs the 3rd party tool currently, the popular one is the Cake.Build.

We need 3 files: build.cake, build.ps1 and tools/packages.config (please see here);

1: Createa a build.cake file (text format) in the root directory of the your site that is generated by Wyam. The content could learn from the cake build file of Dave Glick's blog site or the sample on the Wyam official “Using Cake” page; also we can have learn more from Wyam.Web GitHub project Cake build file or Wyam project on Github Cake build file.

Here is an exmaple:

#tool nuget:?package=Wyam
#addin nuget:?package=Cake.Wyam

// ...

var target = Argument("target", "Default");

Task("Build")
    .Does(() =>
    {
        Wyam(new WyamSettings
        {
            Recipe = "Blog",
            Theme = "CleanBlog",
            UpdatePackages = true
        });   
    });
    
Task("Preview")
    .Does(() =>
    {
        Wyam(new WyamSettings
        {
            Recipe = "Blog",
            Theme = "CleanBlog",
            UpdatePackages = true,
            Preview = true,
            Watch = true
        });         
    });

Task("Default")
    .IsDependentOn("Preview"); 

RunTarget(target);

2: Download the build.ps1 file from Wyam official examples, put this file in the same root directory as build.cake file;

3: The file tools/packages.config could be an optional for most of Wyam generated sites, but if you need it, you can copy from here;

CI (Continious Integration) Pipeline

We use Azure Devops CI/CD. We can either use Microsoft-hosted agents or Self-hosted agents ( About Azure Pipelines agents).

If we use Microsoft-hosted agents, we will have to install the Cake tools for the building:

cake build pipeline tool

If we use Self-hosted agents, we just set a PowerShell Scirpt task in the pipeline:

cake build pipeline tool

CD (Continious Delivery) Pipeline

(Optional) If you need release to Azure Service or other targets, you can set a CD pipeline by add new Release pipeline in Azure Devops. Please check related information from Azure DevOps.

Related links:

1: Cake.Build;
2: Cake on Azure DevOps;