运行 Release Azure Pipeline 时 Powershell 脚本出错

问题描述 投票:0回答:1

我在 Azure DevOps 上创建了一个发布管道并收到 PowerShell 脚本错误消息“进程返回的退出代码 1:文件名‘C:\Windows\System32\WindowsPowerShell 1.0\powershell.exe”,如下图所示,尽管我可以连接通过在 PowerShell 管理员上运行注册脚本来虚拟机。请帮助我通过这个案例

enter image description here

这是我在 Azure 上的 powerShell 配置:enter image description here

azure azure-devops azure-pipelines-release-pipeline
1个回答
0
投票

我尝试运行以下命令在 Azure DevOps 管道中安装 IIS 服务器功能,如下所示:-

我创建了一个自托管代理并在自托管代理 VM 中运行您的命令只是为了检查它是否运行正常:-

enter image description here

我在我的 Azure DevOps YAML 管道中运行了相同的命令,但添加了 Start-Process 命令以管理员身份在提升的状态下启动 PowerShell 任务。

脚本:-

trigger:

- main

  

pool:

name: Default

  

steps:

- script: echo Hello, world!

displayName: 'Run a one-line script'

  

- script: |

echo Add other tasks to build, test, and deploy your project.

echo See https://aka.ms/yaml

displayName: 'Run a multi-line script'

- task: PowerShell@2

inputs:

targetType: 'inline'

script: |

$script = "Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole"

Start-Process powershell.exe -Verb RunAs -ArgumentList '-NoProfile', '-Command', $script

两个命令:-

# Starter pipeline

# Start with a minimal pipeline that you can customize to build and deploy your code.

# Add steps that build, run tests, deploy, and more:

# https://aka.ms/yaml

  

trigger:

- main

  

pool:

name: Default

  

steps:

- script: echo Hello, world!

displayName: 'Run a one-line script'

  

- script: |

echo Add other tasks to build, test, and deploy your project.

echo See https://aka.ms/yaml

displayName: 'Run a multi-line script'

  
  

- task: PowerShell@2

inputs:

targetType: 'inline'

script: |

$script = "Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole"

"Enable-WindowsOptionalFeature -Online -FeatureName ASPNET45 -All"

Start-Process powershell.exe -Verb RunAs -ArgumentList '-NoProfile', '-Command', $script

输出:-

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.