我在 Azure DevOps 上创建了一个发布管道并收到 PowerShell 脚本错误消息“进程返回的退出代码 1:文件名‘C:\Windows\System32\WindowsPowerShell 1.0\powershell.exe”,如下图所示,尽管我可以连接通过在 PowerShell 管理员上运行注册脚本来虚拟机。请帮助我通过这个案例
我尝试运行以下命令在 Azure DevOps 管道中安装 IIS 服务器功能,如下所示:-
我创建了一个自托管代理并在自托管代理 VM 中运行您的命令只是为了检查它是否运行正常:-
我在我的 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
输出:-