Getting started with AppVeyor.

AppVeyor is a Continuous Integration and Continuous Deployment tool that's aimed for .NET developers. In this blog-post I'll take you through the basics for setting up your first Project. We will be building, testing and deploying a PowerShell Module to the PowerShell Gallery using AppVeyor and GitHub.

Getting started.

Before we go into the details you will need fork my AppVeyorDemo repository OR setup your own GitHub repository. Next sign-in and add your project. Every build runs on a fresh (currently Windows 2012r2 x64) virtual machine which is not shared with other builds and the state of which is not preserved between consequent builds. After the build is finished its virtual machine is decommissioned.

Build config (appveyor.yml)

Project builds can be configured by either YAML formatted file or using the AppVeyor user interface. I prefer to use YAML file because it makes it easier to fork/clone or contribute to a project. A minimal YAML is displayed below:

There is not much we need to configure in the YAML file because most parts are handled in linked PowerShell scripts. Nevertheless lets go over the details:

  • version: this is the version number that the build will get. {build} is automatically incremented by AppVeyor with every build. You can change/reset this value in the Projects General settings page
  • os: the Build worker image to use. We will use 'WMF 5'
  • environment: the environment variables to use. You can store both 'secure' and 'non-secure' variables here. You can encrypt a string here. The encrypted string can be stored in the yml file and only your account can decrypt that string in the build process. If another user tries to access it (for example in a pull request) it will not exist. From PowerShell we can access those variables using and we will do so later on.
  • Install, Build, Test, Deploy: we will handle all of these phases from PowerShell. These lines just execute the PowerShell scripts during the build process.


As noted before, the 'install' phase will be handled from PowerShell. Because a new VM is launched for every build, we will need to set some prerequisites. In this example we are going to add the NuGet package provider and install the Pester and PSScriptAnalyzer modules from the PowerShell Gallery as we will require these modules for testing our own modules and/or scripts.

Successful Install

Successful Install


Since we are deploying a simple PowerShell module there is nothing to build. We will just print some info here:

Successful Build

Successful Build


Here is where our testing occurs. We will call the Pester tests from this script (line 11) and upload the results to the AppVeyor API (line 14). Using this approach has the benefit of including the test results as an XML in your repository. If any of the tests fail we will stop the build and will not continue with the deployment phase.

Pester and PSScriptAnalyzer tests

A template Pester and PSScriptAnalyzer tests is shared below (Credits to Ryan Yates). You should be able to keep most of it. Make sure you create some unit tests for your module and replace the 'custom' part of the script below.

Successful Tests

Successful Tests


When all tests have passed we can continue with the deployment. Some things that we take care of here:

  1. Update the module manifest version. We use regex inject the 'APPVEYOR_BUILD_VERSION' environment variable that we configured in the appveyor.yml. (line 12)
  2. Verify the GitHub branch. If the GitHub branch is NOT the master branch we do not want to deploy to the PowerShell Gallery. (line 17)
  3. Adding the project path to the 'psmodulepath' PATH variable". This is required for the 'Publish Module' cmdlet (line 25)
  4. Publish the module. Lastly we publish the module to the PowerShell Gallery. This requires your NuGetApiKey to be correctly configured encrypted and stored in the appveyor.yml file.

Successful Deploy

Successful Deploy

Leave a Comment

Your email address will not be published. Required fields are marked *