How to avoid this error when trying to copy a specific folder from my local system to remote VM using winrm in Jenkins configuration?

1

Am using Powershell script to copy a folder from local system to remote VM.

The below script works fine when am running from my local system.

New-SelfSignedCertificate -DnsName dummy.southcentralus.cloudapp.azure.com -CertStoreLocation Cert:\LocalMachine\My

winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname="dummy.southcentralus.cloudapp.azure.com"; CertificateThumbprint="9C207E7D249D385FDE9D4BBFE7AF7EB008RDGD"}

$pw = convertto-securestring -AsPlainText -Force -String <Password>
$cred = new-object -typename System.Management.Automation.PSCredential - argumentlist <username>,$pw
$session = new-pssession -computername dummy.southcentralus.cloudapp.azure.com -credential $cred
Copy-Item -Path C:\Jenkins\workspace\deploy-service\bin.zip -Destination F:\destpath\bin1.zip -ToSession $session

But when I use the same script in Jenkins at the build step. It throws me an error as given below.

"WinRM cannot process the request. The following error with errorcode 0x8009030d occurred while using Negotiate authentication: A specified logon session does not exist. It may already have been terminated."

What I tried So Far to resolve this error:

  1. I have ensured that winrm is setup on both the host machines involved. Infact with 'Unrestricted' access via set-ExecutionPolicy.
  2. I have Ensured remote machine running as a non-domain user, because local machine is running as a non-domain user.
  3. Used Invoke-Command.
powershell
jenkins
continuous-deployment
asked on Stack Overflow Aug 8, 2019 by Vijay Rajendiran • edited Sep 20, 2019 by Vijay Rajendiran

1 Answer

0

Change in this line, fixed my issue.

$cred = new-object -typename System.Management.Automation.PSCredential - argumentlist <username>,$pw 
as
$cred = new-object -typename System.Management.Automation.PSCredential - argumentlist <domainname>\<username>,$pw

PSCredential, would expect the credential to be with domainname\username rather than passing username alone.

answered on Stack Overflow Aug 9, 2019 by Vijay Rajendiran

User contributions licensed under CC BY-SA 3.0