简体   繁体   English

启动作业导致“后台进程报告错误并显示以下消息:。”

[英]Start-job results in “The background process reported an error with the following message: .”

I have a simple Powershell script (that's being run in a step in Octopus deploy) that I'm trying to run as another user.我有一个简单的 Powershell 脚本(正在 Octopus 部署的一个步骤中运行),我正试图以另一个用户的身份运行它。 We need it for future steps (each application on our platform runs as its own user account, and I need to be able to run an arbitrary script as that user during the deployment process).我们在以后的步骤中需要它(我们平台上的每个应用程序都以其自己的用户帐户运行,并且我需要能够在部署过程中以该用户身份运行任意脚本)。

The problem is that even the simplest script fails with completely unhelpful error messages, such as this:问题是,即使是最简单的脚本也会失败并显示完全无用的错误消息,例如:

$secpasswd = ConvertTo-SecureString $OctopusParameters["runAsPassword"] -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($OctopusParameters["runAsUsername"] , $secpasswd)

$job = Start-Job -scriptblock {
    whoami
} -credential $credential 

$job | Receive-Job -Wait

Which fails with the message:失败并显示以下消息:

The background process reported an error with the following message: .后台进程报告了以下消息的错误:。

The Octopus tentacle is running as a domain account with admin privileges on the machine. Octopus 触手在机器上作为具有管理员权限的域帐户运行。

I've completely exhausted all avenues of investigation now, but we really need to get this working.我现在已经完全用尽了所有的调查途径,但我们真的需要让它发挥作用。 I think if we can't run a deployment script as a certain user then we're completely screwed.我认为如果我们不能以某个用户身份运行部署脚本,那么我们就完蛋了。

Nearly three years later I have the same issue... I tried writing the code to a temporary file and using Start-Process, but couldn't get that to work either.将近三年后,我遇到了同样的问题……我尝试将代码写入临时文件并使用 Start-Process,但也无法使其正常工作。

In the end, I wrote the code to file, and then ran it through the Windows task scheduler.最后,我将代码写入文件,然后通过 Windows 任务调度程序运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM