Skip to content

PowerShell/pwsh steps do not fail on command not found, parameter not found or parameter validation errors #39

@rkeithhill

Description

@rkeithhill

Not sure if this is the correct repo for the GitHub/Azure DevOps powershell action that is used by PowerShell repo to build PowerShell. There's some inception level stuff going on here. :-) Anyway, this issue cropped on a PR build. We were having a hard time figuring out what was going wrong. It turns out that a PowerShell step was indicating it passed when it was clearly failing:

image

In fact, a few experiments with this repo's approach to executing PowerShell script shows that it fails in these other scenarios as well:

image

image

The fix is to execute the wrapper script using try { . 'path-to-ps1' } catch {throw} which causes these issues to return a non-zero exit code:

image

I recently made the same change to the Jenkins durable-task-plugin to fix the very same issue with the powershell/pwsh step in Jenkins pipelines. See my PR for that project.

I would suggest that the following tests for the PowerShell step be added to verify the current impl fails (red/green testing):

- pwsh: Get-CommandDoesNotExist

- pwsh: Get-Date -ParameterDoesNotExist

- pwsh Get-Date -Month 13 # invalid parameter value

- pwsh: Write-Host (1+)  # parse error - I think this works today but good to have a test if you don't already

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions