Jenkins won't run Start-Job with Credential parameter

28 views
Skip to first unread message

red 888

unread,
Sep 12, 2016, 1:25:55 AM9/12/16
to Jenkins Users

I pass in credentials to the script via the env injector (note this works for me with invoke-command) and try to run start-job but jenkins doesn't like it:

$user = $ENV:user
$pass = $ENV:pass

write-output (cat env:username)
write-output (cat env:user)
write-output (cat env:pass)

$pass  = $pass | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential `
  -ArgumentList ($user), $pass

Start-Job -Credential $cred -ScriptBlock {'test'}

write-output (get-job | Receive-Job)
get-job | remove-job

This is the error I get (confirmed username and password are correct, when I run this script from the console with the same creds it works)

Started by user ME

[EnvInject] - Loading node environment variables.
Building in workspace C:\Program Files (x86)\Jenkins\jobs\myjob\workspace
[workspace] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Windows\TEMP\hudson1723222179976241861.ps1'"
MYJENKINSSRV$
correctdomain\correctuser
correctPassword

Id     Name            PSJobTypeName   State         HasMoreData     Location  
--     ----            -------------   -----         -----------     --------  
1      Job1            BackgroundJob   Failed        False           localhost 
[localhost] An error occurred while starting the background process. Error 
reported: Access is denied.
    + CategoryInfo          : OpenError: (localhost:String) [], PSRemotingTran 
   sportException
    + FullyQualifiedErrorId : -2147467259,PSSessionStateBroken


Finished: SUCCESS
Reply all
Reply to author
Forward
0 new messages