[JIRA] (JENKINS-50840) Powershell script execution broken in powershellHelper.ps1

254 views
Skip to first unread message

ghs1@3ds.com (JIRA)

unread,
Apr 17, 2018, 6:31:02 AM4/17/18
to jenkinsc...@googlegroups.com
g hs1 created an issue
 
Jenkins / Bug JENKINS-50840
Powershell script execution broken in powershellHelper.ps1
Issue Type: Bug Bug
Assignee: Unassigned
Components: durable-task-plugin
Created: 2018-04-17 10:30
Environment: Win2008R2 master, Win2016 agent. Jenkins 2.117 and earlier.
Priority: Major Major
Reporter: g hs1

Powershell script execution is broken, possibly after upgrading to durable task pluin 1.22.

11:15:08 out-lineoutput : Object reference not set to an instance of an object.
11:15:08 At C:\Builds\home\workspace\INTG_Lab_Installation_Script_Test\workspace@tmp\durable-19f0c27a\powershellHelper.ps1:25 char:7
11:15:08 +       $Input | Out-String -Stream -Width 192 | ForEach-Object { $Writer.WriteLin ...
11:15:08 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11:15:08     + CategoryInfo          : NotSpecified: (:) [out-lineoutput], NullReferenc    eException
11:15:08     + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShe    ll.Commands.OutLineOutputCommand
11:15:08  

Reverting to 1.17 broke everything

Running in Durability level: MAX_SURVIVABILITY
[Pipeline] End of Pipeline
java.lang.NoSuchMethodError: No such DSL method 'node' found among steps [addBadge, addErrorBadge, addHtmlBadge, addInfoBadge, addShortText, addWarningBadge, ansiColor, archive, build, catchError, checkout, createSummary, deleteDir, dir, echo, error, fileExists, getContext, git, input, isUnix, jiraComment, jiraIssueSelector, jiraSearch, junit, library, libraryResource, load, mail, milestone, p4, p4approve, p4publish, p4sync, p4tag, p4unshelve, parallel, properties, publishHTML, pwd, readFile, readTrusted, removeBadges, removeHtmlBadges, removeSummaries, resolveScm, retry, sleep, stage, stash, step, svn, timeout, timestamps, tm, tool, unarchive, unstash, waitUntil, withContext, withCredentials, withEnv, wrap, writeFile] or symbols [absolute, agent, all, always, ant, antFromApache, antOutcome, antTarget, apiToken, approve, architecture, archiveArtifacts, artifactManager, authorizationMatrix, autoClean, batchFile, bitbucket, booleanParam, buildButton, buildDiscarder, bzt, caseInsensitive, caseSensitive, certificate, checkstyle, choice, choiceParam, ciGame, cleanup, clientSpec, clock, cloud, command, credentials, cron, crumb, defaultView, demand, depotSource, disableConcurrentBuilds, disableResume, dockerCert, downloadSettings, downstream, dumb, durabilityHint, envVars, file, fileCopyOperation, fileCreateOperation, fileDeleteOperation, fileDownloadOperation, fileJoinOperation, fileOperations, fileParam, filePath, filePropertiesToJsonOperation, fileRenameOperation, fileTransformOperation, fileUnTarOperation, fileUnZipOperation, fileZipOperation, fingerprint, fishEye, flushOnly, folderCopyOperation, folderCreateOperation, folderDeleteOperation, folderRenameOperation, forceClean, frameOptions, freeStyle, freeStyleJob, fromScm, fromSource, git, github, githubPush, globalLib, gradle, graphClean, graphSource, headRegexFilter, headWildcardFilter, hyperlink, hyperlinkToModels, incremental, inheriting, inheritingGlobal, installSource, jdk, jdkInstaller, jgit, jgitapache, jnlp, jobName, label, lastDuration, lastFailure, lastGrantedAuthorities, lastStable, lastSuccess, legacy, legacySCM, list, local, location, logRotator, loggedInUsersCanDoAnything, manualSpec, masterBuild, matrix, maven, maven3Mojos, mavenErrors, mavenMojos, mavenWarnings, modernSCM, multiBranch, multiGraph, multiStreams, multiSwarm, myView, nodeProperties, nonInheriting, nonStoredPasswordParam, none, note, openGrok, overrideIndexTriggers, p4Trigger, p4Web, p4cleanup, p4groovy, p4sync, paneStatus, parallel, parameters, password, pathFilter, pattern, perfReport, perforce, performanceReport, performanceTest, pipelineTriggers, plainText, plugin, pollSCM, previewOnly, previous, projectNamingStrategy, proxy, publish, queueItemAuthenticator, quietPeriod, relative, remotingCLI, run, runParam, schedule, scmRetryCount, scriptApprovalLink, search, security, shell, shelve, slave, sourceRegexFilter, sourceWildcardFilter, specFileSpec, sshUserPrivateKey, stackTrace, standard, staticSpec, status, streamSource, streamSpec, string, stringParam, submit, swapSpace, swarm, syncOnly, templateSource, templateSpec, testCase, text, textParam, ticket, ticketMode, tmpSpace, toolLocation, trust, unsecured, unshelve, upstream, user, userFilter, usernameColonPassword, usernamePassword, viewFilter, viewPattern, viewsTabBar, warnings, weather, withAnt, zfs, zip] or globals [currentBuild, env, manager, params, scm]
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:176)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
	at WorkflowScript.run(WorkflowScript:1)
	at ___cps.transform___(Native Method)
	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
	at com.cloudbees.groovy.cps.Next.step(Next.java:83)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Finished: FAILURE

Nothing else was changed. Restoring 1.22 re-introduced the original error.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

ghs1@3ds.com (JIRA)

unread,
Apr 17, 2018, 7:28:02 AM4/17/18
to jenkinsc...@googlegroups.com
g hs1 updated an issue
Change By: g hs1
Powershell script execution is broken, possibly after upgrading to durable task pluin plugin 1.22.
{code:java}

11:15:08 out-lineoutput : Object reference not set to an instance of an object.
11:15:08 At C:\Builds\home\workspace\INTG_Lab_Installation_Script_Test\workspace@tmp\durable-19f0c27a\powershellHelper.ps1:25 char:7
11:15:08 +       $Input | Out-String -Stream -Width 192 | ForEach-Object { $Writer.WriteLin ...
11:15:08 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11:15:08     + CategoryInfo          : NotSpecified: (:) [out-lineoutput], NullReferenc    eException
11:15:08     + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShe    ll.Commands.OutLineOutputCommand
11:15:08  {code}


Reverting to 1.17 broke everything
{code}
{code}


Nothing else was changed. Restoring 1.22 re-introduced the original error.

ghs1@3ds.com (JIRA)

unread,
Apr 17, 2018, 7:30:01 AM4/17/18
to jenkinsc...@googlegroups.com
g hs1 commented on Bug JENKINS-50840
 
Re: Powershell script execution broken in powershellHelper.ps1

Note that the script itself still runs correctly outside of Jenkins.

ghs1@3ds.com (JIRA)

unread,
Apr 17, 2018, 7:31:02 AM4/17/18
to jenkinsc...@googlegroups.com
g hs1 edited a comment on Bug JENKINS-50840
Note that the PowerShell script itself still runs correctly outside of Jenkins. There are no spaces in the job name (JENKINS-48415)

gabloe@microsoft.com (JIRA)

unread,
May 14, 2018, 4:12:02 PM5/14/18
to jenkinsc...@googlegroups.com

gabloe@microsoft.com (JIRA)

unread,
May 14, 2018, 4:37:01 PM5/14/18
to jenkinsc...@googlegroups.com
Gabriel Loewen commented on Bug JENKINS-50840
 
Re: Powershell script execution broken in powershellHelper.ps1

It looks like this is an edge case that is triggered when streaming console output from a powershell script cannot be interpreted as serializable data.  I will work on a fix for this.

gabloe@microsoft.com (JIRA)

unread,
May 15, 2018, 1:11:02 PM5/15/18
to jenkinsc...@googlegroups.com
Gabriel Loewen edited a comment on Bug JENKINS-50840
This edge case seems to be happening only with powershell format cmdlets, such as Format-Table, etc...  Are you using one of these cmdlets?  You can fix it temporarily by piping any calls to Foramt-* cmdlets to Out-String:

e.g.

 
{code:java}
$Data | Format-Table | Out-String{code}
Meanwhile, it should be fixed in my PR: 
[ https://github.com/jenkinsci/durable-task-plugin/pull/70 ]

 

gabloe@microsoft.com (JIRA)

unread,
May 15, 2018, 1:11:02 PM5/15/18
to jenkinsc...@googlegroups.com

This edge case seems to be happening only with powershell format cmdlets, such as Format-Table, etc...  Are you using one of these cmdlets?  You can fix it temporarily by piping any calls to Foramt-* cmdlets to Out-String:

e.g.

 

$Data | Format-Table | Out-String

Meanwhile, it should be fixed in my PR: https://github.com/jenkinsci/durable-task-plugin/pull/70

 

gabloe@microsoft.com (JIRA)

unread,
May 15, 2018, 1:12:02 PM5/15/18
to jenkinsc...@googlegroups.com
Gabriel Loewen edited a comment on Bug JENKINS-50840
This edge case seems to be happening only with powershell format cmdlets, such as Format-Table, etc...  Are you using one of these cmdlets?  You can fix it temporarily by piping any calls to Foramt Format -* cmdlets to Out-String:


e.g.
{code:java}
$Data | Format-Table | Out-String{code}
Meanwhile, it should be fixed in my PR: [https://github.com/jenkinsci/durable-task-plugin/pull/70]

 

ghs1@3ds.com (JIRA)

unread,
May 16, 2018, 3:12:02 AM5/16/18
to jenkinsc...@googlegroups.com
g hs1 commented on Bug JENKINS-50840

Thank you. It doesn't appear so. Here's the script:

Param (
    [Alias("Host")]
    [string]$VIServer = "*******************",
    [string]$vmname = "*******************",
    [string]$admin = "*******************",
    [string]$pathToCredentials
)

#You must change these values to securely save your credential files
$key = *******************

Function Get-Credentials {
    Param (
        [String]$authUser = $env:USERNAME,
        [string]$pathToCred
    )

    #Build the path to the credential file
    $credFile = $authUser.Replace("\","~")
    If (-not $pathToCred){
        $pathToCred = Split-Path $MyInvocation.MyCommand.Path
    }
    $file = Join-Path -Path $pathToCred -ChildPath "\Credentials-$credFile.crd"
    #And find out if it's there, if not create it
    If(-not (Test-Path $file)){
        (Get-Credential $authUser).Password | ConvertFrom-SecureString -Key $key | Set-Content $file
    }
    #Load the credential file
    $password = Get-Content $file | ConvertTo-SecureString -Key $key
    $authUser = (Split-Path $file -Leaf).Substring(12).Replace("~","\")
    $authUser = $authUser.Substring(0,$authUser.Length - 4)
    $credential = New-Object System.Management.Automation.PsCredential($authUser,$password)
    Return $credential
}

If(-not $pathToCredentials){
    $pathToCredentials = Split-Path $MyInvocation.MyCommand.Path
}

Clear-Host

$svr = "*******************"
$snapshot = "*******************"
$cred = Get-Credentials $admin $pathToCredentials
Try{
    Write-Output "Connecting to vSphere server..."
    $vc = Connect-VIServer $VIServer -Credential $cred -ErrorAction Stop 3>$null
    Get-VM -Server $vc -Name $svr | Get-Snapshot | Select VM, Created, Name, SizeMB | FT
    Write-Output "Restoring snapshot..."
    $vm = Get-VM -Server $vc -Name $vmname
    $snapshot = Get-Snapshot -VM $vm -Name $snapshot
    Set-VM -VM $vm -Snapshot $snapshot -Confirm:$false
}
Catch{
    Throw "Error connecting to $VIServer because ""$($Error[1])"""
}
# Exit with 0 unless an exception is thrown.
# Prevents returned values greater than 1 failing the build unnecessarily.
exit 0

It uses VMware's PowerCLI to restore a VM from a snapshot.

Is there any way I can test your fix without waiting weeks or months for a release?

Thanks.

gabloe@microsoft.com (JIRA)

unread,
May 16, 2018, 11:50:02 AM5/16/18
to jenkinsc...@googlegroups.com
Gabriel Loewen edited a comment on Bug JENKINS-50840
The problematic line of code is this one:

 
{code:java}

Get-VM -Server $vc -Name $svr | Get-Snapshot | Select VM, Created, Name, SizeMB | FT
{code}
Here, *FT* is an alias for *Format-Table*, which is what is causing the exception to be thrown. Without taking my fix you could modify that line slightly:

 

 
{code:java}
Get-VM -Server $vc -Name $svr | Get-Snapshot | Select VM, Created, Name, SizeMB | FT | Out-String
{code}
Which should get past the issue. If you want to build and use my latest bits you can always checkout my repo and build it using Maven, and then install the HPI file in your Jenkins instance.

 

gabloe@microsoft.com (JIRA)

unread,
May 16, 2018, 11:50:02 AM5/16/18
to jenkinsc...@googlegroups.com

The problematic line of code is this one:

 

Get-VM -Server $vc -Name $svr | Get-Snapshot | Select VM, Created, Name, SizeMB | FT

Here, FT is an alias for Format-Table, which is what is causing the exception to be thrown. Without taking my fix you could modify that line slightly:

 

 

Get-VM -Server $vc -Name $svr | Get-Snapshot | Select VM, Created, Name, SizeMB | FT | Out-String

Which should get past the issue. If you want to build and use my latest bits you can always checkout my repo and build it using Maven, and then install the HPI file in your Jenkins instance.

 

ghs1@3ds.com (JIRA)

unread,
May 17, 2018, 3:16:02 AM5/17/18
to jenkinsc...@googlegroups.com
g hs1 resolved as Fixed
 

Thank you for your help and for investigating the problem. I'm not set up for Maven so I have applied your workaround and the script is now working.

Change By: g hs1
Status: Open Resolved
Resolution: Fixed

ghs1@3ds.com (JIRA)

unread,
Sep 3, 2018, 5:43:02 AM9/3/18
to jenkinsc...@googlegroups.com
g hs1 closed an issue as Fixed
Change By: g hs1
Status: Resolved Closed
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

edgars.didrihsons@gmail.com (JIRA)

unread,
Nov 14, 2018, 2:58:02 AM11/14/18
to jenkinsc...@googlegroups.com
Edgars Didrihsons commented on Bug JENKINS-50840
 
Re: Powershell script execution broken in powershellHelper.ps1

How is this Fixed when I still encounter it today with Jenkins 2.138.3 and durable-task-plugin 1.27 ? Adding Out-String does help though so thanks for that.

Reply all
Reply to author
Forward
0 new messages