IT Praktyk Blog

How use PowerShell Gallery with AppVeyor?

Posted July 09, 2016; Last update July 10, 2016

Introduction

Recently I played with AppVeyor - they advertise themselves as “#1 Continuous Delivery service for Windows”. I don’t know, I didn’t use other services what are mentioned in the GitHub Integration Directory.

My goals are

Action

I started from read and follow instructions from the article wrote by Warren Frame aka Cookie Monster Fun with Github, Pester, and AppVeyor. Thank you Warren for good article!

Steps

  1. I registered in AppVeyor using my GitHub account,
  2. created a new project and authorized AppVeyor to my GitHub data and access data in my account and GitHub
  3. added the appveyor.yml file to the project and modified it to meet my expectation
  4. committed the appveyor.yml to repository and pushed changes to GitHub

Results

Result 1

The content of appveyor.yml file was like below

install:
  - cinst pester

build: false

test_script:
  - ps: $res = Invoke-Pester -Path ".\Tests" -Tags Tag1 -OutputFormat NUnitXml -OutputFile TestsResults.xml -PassThru
  - ps: (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestsResults.xml))
  - ps: if ($res.FailedCount -gt 0) { throw "$($res.FailedCount) tests failed."}

and Pester tests were evaluated successfully.

Result 2

I updated my appveyor.yml file to include instruction what need to be executed when all tests are passed.

I checked PowerShell version used by AppVeyor build machines and I received information

Name                           Value
----                           -----
PSVersion                      5.0.10586.117
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.10586.117
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

I read documentation about installation in AppVeyor but PowerShell Gallery is not mentioned there.

In my appveyor.yml file I included instructions.

install:
  - cinst pester

build: false

test_script:
  - ps: $res = Invoke-Pester -Path ".\Tests" -Tags Tag1 -OutputFormat NUnitXml -OutputFile TestsResults.xml -PassThru
  - ps: (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestsResults.xml))
  - ps: if ($res.FailedCount -gt 0) { throw "$($res.FailedCount) tests failed."} { Install-Module -Name ModuleName -MinimumVersion 0.3.0 -Repository PSGallery -Force ; <Instruction based on the cmdlet from ModuleName> }

Few minutes - in this time my job was queued - and I received build result. Fail :-(

Exception calling "ShouldContinue" with "2" argument(s): "The method or operation is not implemented."
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:5908 char:8
+     if($Force -or $PSCmdlet.ShouldContinue($shouldContinueQueryMessag ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NotImplementedException

Install-Module : NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
At line:1 char:82
+ ... ."} Else { (Install-Module -Name ModuleName -MinimumVersion 0.3.0 -Repos ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Install-Module], InvalidOperationException
    + FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Module

Result 3

After some probes on my local machine, checking solutions found in Google, I read the Get Started section on the PowerShell Gallery web page once again and I realized that I need modify appveyor.yml file like below.

install:
  - cinst pester

build: false

test_script:
  - ps: $res = Invoke-Pester -Path ".\Tests" -Tags Tag1 -OutputFormat NUnitXml -OutputFile TestsResults.xml -PassThru
  - ps: (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestsResults.xml))
  - ps: if ($res.FailedCount -gt 0) { throw "$($res.FailedCount) tests failed."} { Install-PackageProvider NuGet -MinimumVersion '2.8.5.201' -Force ; Import-PackageProvider NuGet -MinimumVersion '2.8.5.201' -Force ; Install-Module -Name ModuleName -MinimumVersion 0.3.0 -Repository PSGallery -Force ; <Instruction based on the cmdlet from ModuleName> }

artifacts:
  - path: Results

Additionally I added instruction to save the Results of computation - named by AppVeyor as artifacts - they can be next downloaded via web or password protected NuGet repository - more about artifacts you can find here.

I commited changes to repository, pushed to GitHub, wait few minutes and after my job was build successfully :-)

Summary

If you would like use in your build software e.g. modules available in PowerShell Gallery you need add to your project configuration via appveyor.yaml file or AppVeyor web interface line commands

- ps: Install-PackageProvider NuGet -MinimumVersion '2.8.5.201' -Force
- ps: Import-PackageProvider NuGet -MinimumVersion '2.8.5.201' -Force
- ps: Install-Module -Name ModuleName -MinimumVersion X.X.X -Repository PSGallery -Force

Of course these are commands responsible for installing software from PowerShell Gallery only. More about the appveyor.yaml file structure, what is high space chars sensitive, you can read here.

Remarks

  1. I intentionally don’t provide name of module what I install because I prepare the series of blog posts about that.
  2. In the next few hours/day I’ll prepare update for AppVeyor documentation.
  3. I used the AppVeyour plan for open-source projects.