Powershell脚本在运行发布Azure管道时出错

7dl7o3gd  于 2023-02-25  发布在  Shell
关注(0)|答案(1)|浏览(128)

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

tzdcorbm

tzdcorbm1#

我尝试运行以下命令在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
    • 输出:-**

相关问题