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

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/d663fe7f-2f4f-4637-98a5-54faf41aac77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to