Azure管道:启动过程,具有凭据无效

发布于 2025-01-22 13:36:55 字数 2099 浏览 0 评论 0 原文

我正在尝试使用PowerShell从Azure Pipelines YAML启动应用程序。

我希望该应用以非管理员帐户开始,而Azure Pipelines部署代理使用管理员帐户。

为此,我使用的是在部署作业中运行的PowerShell任务,该任务将使用-credentials调用Start -Process:

- task: PowerShell@2
  displayName: 'Start application'
  inputs:
    targetType: 'inline'
    script: |   
        $user = "myOrdinaryUser"
        $PWord = ConvertTo-SecureString -String "myPassword" -AsPlainText -Force

        $credentials = New-Object -TypeName System.Management.Automation.PSCredential ($user, $PWord)

        $process = Start-Process -FilePath "C:\Windows\notepad.exe" -PassThru -Credential $credentials -WorkingDirectory 'C:\Windows' -RedirectStandardOutput myOutputLogFile -RedirectStandardError myErrorLogFile
        

         Write-Host "Process ExitCode: " $process.ExitCode
         Write-Host "Process id: " $process.Id
         Write-Host "Process name: " $process.Name
         Write-Host "HasExited: " $process.HasExited
         Write-Host "StartTime: " $process.StartTime
         Write-Host "ExitTime: " $process.ExitTime

但是它不起作用。

输出:

Process ExitCode:

进程ID:11408

过程名称:

已验证:true

开始时间:

出口:

两个输出日志文件都可以创建,但没有任何内容。

在evend查看器中,在Windows日志下 - >系统,有消息

来源:应用程序弹出

Notepad.exe-应用程序错误

该应用程序无法正确启动(0xc0000142)。 单击确定关闭应用程序。

如果我在没有凭据的情况下做同样的事情,它可以起作用。但是,当作业完成时,该应用程序关闭。显然,这是设计:

$process = Start-Process -FilePath "C:\Windows\notepad.exe" -PassThru

输出:

Process ExitCode:

进程ID:10024

过程名称:记事本

已验证:false

开始时间:19-04-2022 16:23:52

出口:

另外,如果我在PowerShell提示中运行PS脚本,则可以与凭证一起使用。

如何获得有关为什么该过程不启动的更多信息以及如何修复该过程?

I am trying to start an application from Azure Pipelines YAML using Powershell.

I want the app to start with a non-administrator account, while the Azure Pipelines deployment agent uses an administrator account.

To do this, I am using a Powershell task running in a deployment job that calls Start-Process with -Credentials:

- task: PowerShell@2
  displayName: 'Start application'
  inputs:
    targetType: 'inline'
    script: |   
        $user = "myOrdinaryUser"
        $PWord = ConvertTo-SecureString -String "myPassword" -AsPlainText -Force

        $credentials = New-Object -TypeName System.Management.Automation.PSCredential ($user, $PWord)

        $process = Start-Process -FilePath "C:\Windows\notepad.exe" -PassThru -Credential $credentials -WorkingDirectory 'C:\Windows' -RedirectStandardOutput myOutputLogFile -RedirectStandardError myErrorLogFile
        

         Write-Host "Process ExitCode: " $process.ExitCode
         Write-Host "Process id: " $process.Id
         Write-Host "Process name: " $process.Name
         Write-Host "HasExited: " $process.HasExited
         Write-Host "StartTime: " $process.StartTime
         Write-Host "ExitTime: " $process.ExitTime

But it does not work.

Output:

Process ExitCode:

Process id: 11408

Process name:

HasExited: True

StartTime:

ExitTime:

Both the output log files get created, but contain nothing.

In Event Viewer, under Windows Logs -> System, there is the message

Source: Application Popup

notepad.exe - Application Error

The application was unable to start correctly (0xc0000142).
Click OK to close the application.

If I do the same without credentials, it works. However, the app closes when the job finishes. Apparently, this is by design:
https://developercommunity.visualstudio.com/t/starting-a-process-from-azure-deployment-agent-tas/1038946

$process = Start-Process -FilePath "C:\Windows\notepad.exe" -PassThru

Output:

Process ExitCode:

Process id: 10024

Process name: notepad

HasExited: False

StartTime: 19-04-2022 16:23:52

ExitTime:

Also, If I run the PS script in a Powershell prompt it works with credentials.

How can I get more information about why the process does not start and how do I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑梦风尘 2025-01-29 13:36:55

我通过以下解决方法解决了这一点:

1。
使用事件日志触发器创建一个Windows任务,该任务在正确的用户帐户下运行该应用程序。

然后,用此PowerShell命令替换启动过程:

Write-EventLog -LogName "Application" -Source "MySource" -EventID 999 -Message "Start application"

安装了构建代理,而不是部署/资源代理。
配置为在交互模式下运行。

在此模式下,使用-credential使用启动过程。

I solved this with the following workarounds:

1.
Created a Windows Task with an event log trigger that runs the app under the correct user account.

Then, replaced Start-Process with this Powershell command:

Write-EventLog -LogName "Application" -Source "MySource" -EventID 999 -Message "Start application"

Installed a build agent instead of a deployment/resource agent.
Configured to run in Interactive mode.

Start-Process works using -Credential in this mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文