1

I have a PowerShell module on github which has automation on AppVeyor including testing and publishing.

One of the recent changes broke the new version with Windows PowerShell. Some groups still run on Windows PowerShell and they informed me about this (former colleagues).

My question is if and how can a given module be tested for both versions with Pester. Obviously on a windows system you can run the test with pwsh or powershell but I wonder if there is a cleaner setup powered by Pester v5.

On top of that, I wonder how would this be possible with AppVeyor because from the doc there is no image with both v5 and v7 of powershell? As an alternative, the doc mentions that multiple images can be used but I don't understand what will happen. The goal is to test on windows and core and publish once.

Alex Sarafian
  • 634
  • 6
  • 17
  • Regarding your last question: [Use multiple images](https://www.appveyor.com/docs/build-environment/#using-multiple-images-for-the-same-build) – Mathias R. Jessen Sep 20 '21 at 17:49

1 Answers1

0

I used to do this via AppVeyor for some of my PowerShell modules. My use case was actually to test under Linux as well as Windows, but in doing so I was effectively testing on PS Core and Windows PowerShell. The module is no longer using AppVeyor, but I went back in the commit history and pulled the below from its appveyor.yml.

As Mathias said, you want to use multiple images and you can have also have different images run different build scripts if needed:


image:
- WMF 5
- Ubuntu
- Visual Studio 2017

# Skip on updates to the readme.
# We can force this by adding [skip ci] or [ci skip] anywhere in commit message 
skip_commits:
  message: /updated README.*|update README.*s/

build: false

#Kick off the CI/CD pipeline
test_script:
  - pwsh: .\build.ps1

for:
-
  matrix:
    only:
      - image: WMF 5
  
  test_script:
  - ps: .\build.ps1

This uses 3 images I think because it was testing on Windows PowerShell, PS Core on Ubuntu and PS Core on Windows.

Mark Wragg
  • 22,105
  • 7
  • 39
  • 68
  • Thank you. Your goals are identical to mine and the linux/windows image is how I thought about it as well. From your yaml file, I'm not sure I understand how does this differ per immage because you have the same `build.ps1` invocation without any conditions. My question is how do the images stack for testing and one publish. I assume, all images do the test and the last one does the publish (if the other images are okay) and you control this with variables and parameters etc. – Alex Sarafian Sep 21 '21 at 08:13
  • Your right it is the same build.ps1, but one is invoked via `pwsh` which uses PowerShell Core, the other via `ps` which uses Windows PowerShell. I think when I used it I just had the last image do the publish, but beware I think they might execute in parallel by default. – Mark Wragg Sep 21 '21 at 08:46