[JIRA] (JENKINS-60423) Powershell fails when the script starts with 'CmdletBinding' attribut

14 views
Skip to first unread message

admiral.soruk@gmail.com (JIRA)

unread,
Dec 10, 2019, 10:59:02 AM12/10/19
to jenkinsc...@googlegroups.com
Aleksander Kasprzyk created an issue
 
Jenkins / Bug JENKINS-60423
Powershell fails when the script starts with 'CmdletBinding' attribut
Issue Type: Bug Bug
Assignee: Unassigned
Components: powershell-plugin
Created: 2019-12-10 15:58
Labels: powershell
Priority: Major Major
Reporter: Aleksander Kasprzyk

Hi, 

 

Since upgrade to the latest version of PowerShell Plugin (1.4) a lot of my scripts does not work any more.

Especially when inline or script files starts with the 'CmdletBinding' attribut.

[workspace] $ powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File C:\Users\ATHICS~1\AppData\Local\Temp\jenkins8862236051379677851.ps1

Au caractŠre C:\Users\AthicService\AppData\Local\Temp\jenkins8862236051379677851.ps1:3 : 1

+ [CmdletBinding()]

~+ ~~~~~~~~~~~~~~~~~~

Attribut inattendu ®ÿCmdletBindingÿ¯.

Au caractŠre C:\Users\AthicService\AppData\Local\Temp\jenkins8862236051379677851.ps1:4 : 1

+ param([switch]$Elevated

~+ ~~~~~~

Jeton inattendu ®ÿparamÿ¯ dans l'expression ou l'instruction.

    + CategoryInfo          : ParserError: ( [], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : UnexpectedAttribute

 

Build step 'PowerShell' marked build as failure

 

 

As I have a lot of PS scripts like that, I have to downgrade to 1.3 version.

 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

kahmeal@gmail.com (JIRA)

unread,
Feb 17, 2020, 1:50:03 PM2/17/20
to jenkinsc...@googlegroups.com
Kamil Mackow commented on Bug JENKINS-60423
 
Re: Powershell fails when the script starts with 'CmdletBinding' attribut

Seeing a similar issue in our scripts since updating to latest. Rolling back fixes the issue.

 

$ powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File C:\Users\SVC-JE~1\AppData\Local\Temp\2\jenkins310832792838059245.ps1
At C:\Users\svc-jenkins_dev\AppData\Local\Temp\2\jenkins310832792838059245.ps1:3 char:79
+ ... lias("BuildConfiguration")][String] $build_configuration = "Release",
+                                                                ~~~~~~~~~
The assignment expression is not valid. The input to an assignment operator must be an object that is able to accept 
assignments, such as a variable or a property.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidLeftHandSide
 
Build step 'PowerShell' marked build as failure

Top of one of the offending scripts:

Param(   
    [parameter()][Alias("BuildConfiguration")][String] $build_configuration = "Release",
    [parameter()][Alias("Test")][Switch] $run_tests,
    [parameter()][Alias("Analyze")][Switch] $run_analysis,
    [parameter()][Alias("Coverage")][Switch] $enforce_coverage,
    [parameter()][Alias("MinCoverage")][int] $min_coverage = 50
)

owen@nerdnetworks.org (JIRA)

unread,
Mar 9, 2020, 8:15:02 PM3/9/20
to jenkinsc...@googlegroups.com
Owen Mehegan assigned an issue to Filipe Roque
 
Change By: Owen Mehegan
Assignee: Filipe Roque
This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38)
Atlassian logo

froque@premium-minds.com (JIRA)

unread,
Mar 10, 2020, 7:00:02 AM3/10/20
to jenkinsc...@googlegroups.com
Filipe Roque commented on Bug JENKINS-60423
 
Re: Powershell fails when the script starts with 'CmdletBinding' attribut

I'am able to reproduce the problem with the following script:
 

param(
    [Parameter()][String] $Param1 = "this parameter #1",
    [Parameter()][String] $Param2 = "this parameter #2"
)

Write-Host $Param1
Write-Host $Param2

This runs fine, directly in the powershell:

$ pwsh -NonInteractive -File Script.ps1 
this parameter #1
this parameter #2

But, powershell version 1.4, prepends '$ErrorActionPreference="Stop"' or '$ErrorActionPreference="Continue"' to the script:

$ErrorActionPreference="Continue"
param(
    [Parameter()][String] $Param1 = "this parameter #1",
    [Parameter()][String] $Param2 = "this parameter #2"
)

Write-Host $Param1
Write-Host $Param2
$ pwsh -NonInteractive -File Script.ps1 
ParserError: /home/froque/repos/jenkins-workspace/powershell-plugin/Script.ps1:3
Line |
   3 |      [Parameter()][String] $Param1 = "this parameter #1",
     |                                      ~~~~~~~~~~~~~~~~~~~
     | The assignment expression is not valid. The input to an assignment operator must be an object that is able to accept assignments, such as a variable or a property.

 

Kamil Mackow Aleksander Kasprzyk My question to you is: What's the point in defining these parameters, if there is no way to define its values? I fail to see how is this useful. A use case would be helpful.

I could change the plugin only add '$ErrorActionPreference="Stop"' if configured as such or something else like it.

admiral.soruk@gmail.com (JIRA)

unread,
Mar 10, 2020, 9:09:02 AM3/10/20
to jenkinsc...@googlegroups.com

Hi Filipe Roque,

I'm using the Standard PowerShell arguments, like -ErrorAction and -Verbose in my scripts that are set up before the call from Jenkins (as constants or as Jenkins Job parameter).

For exemple, the -ErrorAction is sometimes "Stop" or "SilentlyContinue", depending of a given need.

And a script might be called outside Jenkins.

Param ( 
 [string]$workspace = $ENV:WORKSPACE,
 [string]$buildMode = $ENV:BUILD_MODE
)
$script = Join-Path $workspace "AthicAuthentication.$buildMode.ps1"
$code = 0
if (Test-Path -Path $script -ErrorAction SilentlyContinue) {
 $code = Invoke-Expression "$script" -ErrorAction Stop
}
exit $code

What changed between 1.3 and 1.4 version that causes this issues ?

kahmeal@gmail.com (JIRA)

unread,
Mar 10, 2020, 3:59:03 PM3/10/20
to jenkinsc...@googlegroups.com

Hi Filipe Roque,

We use these parameters as default values as these scripts are included in some of our build repositories and having commonly used defaults is a nice convenience for end users so they don't have to know every value but can override if they choose to without modifying the script itself.

Does that answer the question?

owen@nerdnetworks.org (JIRA)

unread,
Mar 11, 2020, 2:05:03 AM3/11/20
to jenkinsc...@googlegroups.com

Filipe Roque this plugin does not appear to have a default assignee in Jira. I assigned this to you because a CloudBees customer was impacted by this issue, and after I figured out the cause I saw that you did most of the recent work on it. If you will be maintaining the plugin going forward, let me know and I can make you the default assignee for new Jira issues so you will see them.

froque@premium-minds.com (JIRA)

unread,
Mar 11, 2020, 5:58:02 AM3/11/20
to jenkinsc...@googlegroups.com

Owen Mehegan I became a maintainer for this plugin a couple of months ago. yes, please make me the default assignee. If you could, please make me the default assignee for the plugin-usage-plugin as well, as I also became a maintainer for that plugin, last week.

As for the issue, It is my understanding, that people are reusing existing scripts and pasting directly to the powershell plugin. A will take a look at it.

owen@nerdnetworks.org (JIRA)

unread,
Mar 13, 2020, 2:19:03 AM3/13/20
to jenkinsc...@googlegroups.com

Filipe Roque OK, I have made you the default assignee for those two plugins. 

Reply all
Reply to author
Forward
0 new messages