Open plastikfan opened 4 years ago
This tutorial has a problem in that the pipeline fails due to Pester (version 0) not being found. I created a new organisation (purely for testing purposes, called Winjer) and then created a project within Winjer called Hoopla. The Pester module was installed into Winjer, but the pipeline just fails. The only good thing about this so far is there is a complete yaml pipleline file (see below), perhaps I can derive my own pipleline from this one. Using Azure Pipelines is proving to be a very long-winded pain in the butt, so I may have to consider using Github actions instead.
The pipeline:
trigger:
- master
name: 'PowerShell Module Project'
variables:
major: 0
minor: 0
patch: $(Build.BuildID)
buildVer: $(major).$(minor).$(Build.BuildID)
pool:
vmImage: "ubuntu-latest"
stages:
- stage: Build
jobs:
- job: Build
steps:
- task: PowerShell@2
inputs:
filePath: '$(System.DefaultWorkingDirectory)/build_scripts/build.ps1'
- task: NuGetCommand@2
inputs:
command: 'pack'
packagesToPack: '$(System.DefaultWorkingDirectory)/PowerShellModuleProject.nuspec'
versioningScheme: byEnvVar
versionEnvVar: buildVer
buildProperties: 'VERSIONHERE=$(buildVer)'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'NuGetPackage'
publishLocation: 'Container'
- stage: Test
jobs:
- job: Test
steps:
- task: Pester@0
inputs:
scriptFolder: "@{Path='$(System.DefaultWorkingDirectory)/PowerShellModuleProject.Tests.ps1'"
resultsFile: "$(System.DefaultWorkingDirectory)/PowerShellModuleProject.Tests.XML"
usePSCore: true
run32Bit: False
- task: PublishTestResults@2
inputs:
testResultsFormat: "NUnit"
testResultsFiles: "$(System.DefaultWorkingDirectory)/PowerShellModuleProject.Tests.XML"
failTaskOnFailedTests: true
- stage: Deploy
jobs:
- job: Deploy
steps:
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: 'NuGetPackage'
itemPattern: '**'
targetPath: '$(Pipeline.Workspace)'
- task: NuGetCommand@2
inputs:
command: 'push'
packagesToPush: '$(Pipeline.Workspace)/**/*.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'adbertram'
I updated the pester task, (should be Pester 10, not 0) and the build stage passes.
However, the Test stage fails with a different error:
##[error]Get-ChildItem: /home/vsts/.local/share/powershell/Modules/Pester/5.0.3/Pester.psm1:3159
Line |
3159 | Get-ChildItem -Recurse -Path $p -Filter "*$Extension" -Fi …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot find path
| '/home/vsts/work/1/s/@{Path='/home/vsts/work/1/s/' because it
| does not exist.
##[error]Get-ChildItem: /home/vsts/.local/share/powershell/Modules/Pester/5.0.3/Pester.psm1:3159
Line |
3159 | Get-ChildItem -Recurse -Path $p -Filter "*$Extension" -Fi …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot find path
| '/home/vsts/work/1/s/@{Path='/home/vsts/work/1/s/' because it
| does not exist.
I found that there is a problem with this task:
- task: Pester@10
inputs:
scriptFolder: "@{Path='$(System.DefaultWorkingDirectory)/PowerShellModuleProject.Tests.ps1'"
resultsFile: "$(System.DefaultWorkingDirectory)/PowerShellModuleProject.Tests.XML"
usePSCore: true
run32Bit: False
I don't know exactly what the problem is:
##[error]Get-ChildItem: /home/vsts/.local/share/powershell/Modules/Pester/5.0.3/Pester.psm1:3159
Line |
3159 | Get-ChildItem -Recurse -Path $p -Filter "*$Extension" -Fi …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot find path
| '/home/vsts/work/1/s/@{Path='/home/vsts/work/1/s/' because it
| does not exist.
but if you delete it, and re-create it (Pester task in the online UI), it creates this instead:
- task: Pester@10
inputs:
scriptFolder: '$(System.DefaultWorkingDirectory)\*'
resultsFile: '$(System.DefaultWorkingDirectory)\Test-Pester.XML'
usePSCore: False
which does work.
On to the next problem:
##[error]Should: /home/vsts/work/1/s/PowerShellModuleProject.Tests.ps1:6
Line |
6 | … \PowerShellModuleProject.psm1" -ErrorAction Stop } | should not throw
| ~~~~~~~~~~~~~~~~
| Legacy Should syntax (without dashes) is not supported in
| Pester 5. Please refer to migration guide at:
| https://pester.dev/docs/migrations/v3-to-v4
... this is just showing that incorrect syntax is being used in test. WIth v5 of Pester, the not must be preceded with a -.
so when you fix this, there is another problem in that 1 of the tests fails to run due to a parameter binding issue:
[-] Module-level tests.the module imports successfully
92ms (54ms|37ms)
ParameterBindingException: Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.
at <ScriptBlock>, /home/vsts/work/1/s/PowerShellModuleProject.Tests.ps1:6
and line 6 is:
{ Import-Module -Name "$PSScriptRoot\PowerShellModuleProject.psm1" -ErrorAction Stop } | should -not throw
So, it maybe better to abandon this repo and use my own (FakeBuddy), the project I set up pure to test Azure; at least I know the tests run ok.
Raised this issue
See this on stackoverflow: Pipelines Powershell Task - One session across mutliple tasks
I renamed the poorly named bootstap.ps1 to do-pipeline.ps1 then performed the build/test and doc build in the same file, then re-wrote the pipleline to be:
name: $(Build.DefinitionName)_$(Date:yyyyMMdd))
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
major: 0
minor: 0
patch: $(Build.BuildID)
buildVersion: $(major).$(minor).$(patch)
system.debug: true
stages:
- stage: Build
jobs:
- job: Build
steps:
- powershell: ./do-pipeline.ps1
displayName: 'Run Pipeline'
A simple pipeline, that actually works, but there is no fine grain control.
I am going to have to try the Pester Azure Extension again since this does work after the bootstrap process, but I will have to ignore the invoke-build script and control all testing via the Pester extension.
This is the issue I raised on Pester AzureDevOpsExtension
This pipeline (from AzureDevOpsExtension) shows how to retrieve the version number of yuour module.
This repo defines an Azure pipeline: AzOps And another azure-powershell And this: xWebAdministration
Using this tutirial https://adamtheautomator.com/azure-devops-powershell-module-pipeline/