[JIRA] (JENKINS-61866) Pipeline fails to detect failed powershell step

4 views
Skip to first unread message

adm.malax+jenkins@gmail.com (JIRA)

unread,
Apr 10, 2020, 7:39:03 AM4/10/20
to jenkinsc...@googlegroups.com
Sergey Dedik created an issue
 
Jenkins / Bug JENKINS-61866
Pipeline fails to detect failed powershell step
Issue Type: Bug Bug
Assignee: Unassigned
Components: core, pipeline
Created: 2020-04-10 11:38
Environment: Jenkins version 2.222.1
Pipeline plugin version 2.6
Pipeline: Nodes and Processes plugin version 2.35
Labels: jenkins pipeline powershell failure
Priority: Major Major
Reporter: Sergey Dedik

Consider following scripted pipeline:

 node ('windows') {
    stage ("stage 1") {
        powershell '''
            & C:\\Temp\\test.ps1
        '''
    }
    
    stage ("stage 2") {
        echo "stage 2"
    }
}

Contents of the test.ps1 is following:

param ($param1)

$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest

Write-Host $undefVar

The script is specifically designed to fail on trying to access undefined variable. This scenario is working correctly, Jenkins detects that PowerShell script returned something other than 0 exit code and fails pipeline execution.

However! If the script to be changed this way (only line 1 has changed):

param ([Parameter(Mandatory=$false)] $param1)

$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest

Write-Host $undefVar

Then the script fails exactly the same way, but Jenkins fails to detect this failure and proceeds to execute stage 2.

Invoking both versions of the PowerShell script manually shows that in both cases powershell process exit code is 1. I fail to understand how adding parameter attribute to PowerShell script affects Jenkins ability to detect script outcome.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages