Wednesday 15 July 2015

Powershell job with alternate credentials from Octopus Deploy -



Powershell job with alternate credentials from Octopus Deploy -

i've got octopus tentacle running deploy script. tentacle running localsystem account.

inside script, i'm able pretty much need, aside archive bit. archive needs done under different domain credentials because it's on network share.

the frustrating code below works locally, when run off tentacles, fails error

----------------------------------------------------[ backup nupkg ]---------------------------------------------------- storing backup version of geosphere.1.2.1.1722.nupkg development environment error 09:24:32 [localhost] there error launching the background process. error error 09:24:32 reported: access is denied. error 09:24:32 at c:\octopus\deployments\development\geosphere\1.2.1.1722\deploy.ps1:121 error 09:24:32 char:1 error 09:24:32 + receive-job $job error 09:24:32 + ~~~~~~~~~~~~~~~~ error 09:24:32 + categoryinfo : openerror: (localhost:string) [], psremotingtran error 09:24:32 sportexception error 09:24:32 + fullyqualifiederrorid : -2147467259,pssessionstatebroken info 09:24:32 hasmoredata : false statusmessage : location : localhost command : import-module $args[3] backup-nupkg $args[0] $args[1] $args[2] jobstateinfo : failed finished : system.threading.manualresetevent instanceid : 0c031592-4c2a-4f8b-b014-a5ba79be09f7 id : 1 name : job1 childjobs : {job2} psbegintime : 13/11/2014 9:24:30 am psendtime : 13/11/2014 9:24:31 psjobtypename : backgroundjob output : {} error : {} progress : {} verbose : {} debug : {} warning : {} state : failed fatal 09:24:32 powershell script returned non-zero exit code: 1 tentacle version 2.5.11.614

here's code

$pwd = convertto-securestring "[password]" -asplaintext -force $cred=new-object -typename system.management.automation.pscredential -argumentlist "[domain\user]",$pwd $packagename = "geosphere.$version.nupkg" $backuppath = $($es.backuppath) $artifactspath = $($es.artifactspath) $job = start-job -scriptblock { import-module $args[3] backup-nupkg $args[0] $args[1] $args[2] } -argumentlist @($packagename,$backuppath,$artifactspath,"$currentdir\modules\applicationutilities") -credential $cred wait-job $job receive-job $job

here's applicationutilities module

function backup-nupkg{ param( [parameter(mandatory=$true,position=0)] [string] $packagename, [parameter(mandatory=$true,position=1)] [string] $backuppath, [parameter(mandatory=$true,position=2)] [string] $artifactspath ) if(!(test-path $($backuppath))) { md $($backuppath) } else { remove-item "$($backuppath)\*" -recurse -force } copy-item $artifactspath\$packagename $backuppath } export-modulemember backup-nupkg

what magic trick getting run off of tentacle locally?

i tried same thing without luck, seems it's not possible start jobs different user. in similar question, leblanc ended using winrm , invoke-command instead:

run script block specific user powershell

(i don't think octopus specific - issue seems more of problem scheme beingness able start processes different user, or start-job under system, or perhaps both)

powershell credentials octopus-deploy

No comments:

Post a Comment