2014-11-13 27 views
5

我有一個運行部署腳本的Octopus Tentacle。觸手以LocalSystem帳戶運行。使用Octopus Deploy中備用憑據的PowerShell作業

在腳本里面,除了一些存檔位之外,我幾乎可以做任何我需要的東西。檔案需要在不同的域憑證下完成,因爲它在網絡共享上。

令人沮喪的這是下面的代碼本地工作,但在逃跑的觸角,它失敗,出現錯誤

----------------------------------------------------[ Backup Nupkg ]---------------------------------------------------- Storing a backup version of GeoSphere.1.2.1.1722.nupkg for the Development environment
Error 09:24:32 [localhost] There is an 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 AM PSJobTypeName : BackgroundJob
Output : {} Error : {} Progress : {} Verbose
: {} Debug : {} Warning : {} State : Failed
Fatal 09:24:32 PowerShell script returned a non-zero exit code: 1
Tentacle version 2.5.11.614

下面的代碼

$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 

這裏的ApplicationUtilities模塊

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 

讓這個跑掉的魔術是什麼?觸手,因爲它在本地?

+0

此外,我試圖讓觸手服務作爲指定用戶運行,但後來我得到一個IIS配置問題,引發另一個扳手混合。這些冒險的認證問題是痛苦的。 –

回答

6

我嘗試了同樣的事情沒有任何運氣,似乎它不可能作爲一個不同的用戶開始工作。在這種類似的問題,勒布朗最終使用WinRM和Invoke-Command代替:

run script block as a specific user with Powershell

(我不認爲這是什麼八達通具體 - 這個問題似乎是更多的問題與系統能夠啓動進程作爲一個不同的用戶,或與系統下的Start-Job或可能兩者)

+0

謝謝保羅。我將服務帳戶更改爲具有管理員憑據的帳戶。從那裏我就可以做副本,甚至不需要開始新的工作。 –

相關問題