Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-49159

Cannot run Powershell Start-Job with credentials passed from Jenkins

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • powershell-plugin
    • None

      I'm trying to run powershell script with Start-Job inside via Jenkins Windows slave.

      User's credentials are passed into script from Jenkins. 

      In this scenarion job always finished with powershell error:

      The background process reported an error with the following message: .

      12:03:05     + CategoryInfo          : OpenError: (localhost:String) [], PSRemotingTransportException

      12:03:05     + FullyQualifiedErrorId : 2100,PSSessionStateBroken

       

      I can't solution for this, so maybe this is a bug.

          [JENKINS-49159] Cannot run Powershell Start-Job with credentials passed from Jenkins

          I've run into apparently similar issue (going by the error message), although I simply hardcoded the credentials into the script itself.

          After reading this, I changed the username format from user to \user and the remote command executed without issues.

          Michal Zatloukal added a comment - I've run into apparently similar issue (going by the error message), although I simply hardcoded the credentials into the script itself. After reading this , I changed the username format from user to \user and the remote command executed without issues.

          Alexander Bakker added a comment - - edited

          I'm encountering the exact same issue. Some additional information that may help to narrow this down:

          • It is invoked as follows:
            $job = Start-Job -Credential $cred -ArgumentList ($arg1, $arg2) -ScriptBlock { }
            $job | Receive-Job -AutoRemoveJob -Wait

            Where $cred is a PSCredential.

          • Jenkins is running as "Local Service" on Windows Server 2019.
          • The script with Start-Job in it runs fine when run from a PowerShell prompt on the same machine. The issue only occurs when Jenkins runs the PowerShell script.
          • The workaround that myxal suggested does not work for me.

          I'm kind of at a loss here. If anyone has any suggestions how I could help debug this issue, please let me know.

          Alexander Bakker added a comment - - edited I'm encountering the exact same issue. Some additional information that may help to narrow this down: It is invoked as follows: $job = Start-Job -Credential $cred -ArgumentList ($arg1, $arg2) -ScriptBlock { } $job | Receive-Job -AutoRemoveJob -Wait Where $cred is a PSCredential. Jenkins is running as "Local Service" on Windows Server 2019. The script with Start-Job in it runs fine when run from a PowerShell prompt on the same machine. The issue only occurs when Jenkins runs the PowerShell script. The workaround that myxal suggested does not work for me. I'm kind of at a loss here. If anyone has any suggestions how I could help debug this issue, please let me know.

          I'm currently working around this issue by using Invoke-Command instead, and allowing PowerShell Remoting sessions with CredSSP authentication on localhost from localhost.

          Alexander Bakker added a comment - I'm currently working around this issue by using Invoke-Command instead, and allowing PowerShell Remoting sessions with CredSSP authentication on localhost from localhost.

          Avi Huly added a comment -

          I am having the exec same issue, is there any update?

          Avi Huly added a comment - I am having the exec same issue, is there any update?

            Unassigned Unassigned
            pawell Pavel Polushin
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: