-
Bug
-
Resolution: Unresolved
-
Minor
-
Jenkins 2.249.2, Windows 10 v2004, PowerShell 7.0.3
I have only tested this on Windows 10, I am not sure if the same issue is present on other operating systems. Also note that this is NOT related to the PowerShell plugin (which I have not installed)but specific to using PowerShell within a pipeline.
To replicate:
1) Install the latest version of PowerShell on Windows 10 (PowerShell 7.0.3).
2) Install the latest LTS version of Jenkins on Windows 10, choose the option to install the default plugins.
3) Choose New item > Pipeline
4) Leave all the default options alone.
5) Copy-paste the following into the "pipeline script" section:
pipeline {
agent any
stages {
stage('Test') {
steps {
script
script
{ stdo = pwsh(returnStdout: true, script: ''' Write-Error 'PowerShell 7: Error 1' ''') echo stdo }script
{ powershell(script: ''' Write-Error 'PowerShell 5.1: Error 2' ''') }script
{ pwsh(script: ''' Write-Error 'PowerShell 7: Error 2' ''') } }
}
}
}
6) Note that the error messages print fine in PowerShell 5.1 but NOT in PowerShell 7. Also note that the build shows as "SUCCESS" despite all the errors, which seems to be an issue with both PowerShell 5.1 and PowerShell 7 unless the $ErrorActionPreference variable is set to "Stop" manually (more details here: https://www.reddit.com/r/jenkinsci/comments/jb6591/powershell_pipeline_example_doesnt_return/).
Output:
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in C:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\PowerShell\PowerShell-pipeline5
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] script
[Pipeline] {
[Pipeline] powershell
C:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\PowerShell\PowerShell-pipeline5@tmp\durable-89bdf695\powershellScript.ps1 : PowerShell 5.1: Error 1
At C:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\PowerShell\PowerShell-pipeline5@tmp\durable-89bdf695\powershellHelper.ps1:54 char:9
+ &
*>&1 | ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: ( [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellScript.ps1
[Pipeline] echo
[Pipeline] }
[Pipeline] // script
[Pipeline] script
[Pipeline] {
[Pipeline] pwsh
[91mWrite-Error: [0mC:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\PowerShell\PowerShell-pipeline5@tmp\durable-8222dfc6\powershellHelper.ps1:54
[96mLine |
[96m 54 | [0m &
*>&1 | …
[96m | [91m ~~~~~~~~~~~~~
[91m[96m | [91mPowerShell 7: Error 1
[0m
[Pipeline] echo
[Pipeline] }
[Pipeline] // script
[Pipeline] script
[Pipeline]
[Pipeline] // script
[Pipeline] script
[Pipeline]
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[Checks API] No suitable checks publisher found.
Finished: SUCCESS