Azure 管道错误“Windows PowerShell 处于非交互模式。”

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

我正在使用 power shell 脚本在 Windows 10 Pro 机器上安装 IIS。 我正在使用这个 blog post 来创建脚本。

脚本使用以下核心安装 IIS。

# * Make sure you run this script from a Powershel Admin Prompt!
# * Make sure Powershell Execution Policy is bypassed to run these scripts:
# * YOU MAY HAVE TO RUN THIS COMMAND PRIOR TO RUNNING THIS SCRIPT!
Set-ExecutionPolicy Bypass -Scope Process

# To list all Windows Features: dism /online /Get-Features
# Get-WindowsOptionalFeature -Online 
# LIST All IIS FEATURES: 
# Get-WindowsOptionalFeature -Online | where FeatureName -like 'IIS-*'

Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServer
Enable-WindowsOptionalFeature -Online -FeatureName IIS-CommonHttpFeatures
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpErrors
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpRedirect
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationDevelopment

我已经在 DevOps 上完成了任务:

一切正常,但今天当我开始部署时,开始出现错误

Enable-WindowsOptionalFeature:Windows PowerShell 处于非交互模式。阅读和提示功能不是 可用的。 在 C: zagent\A1_work_temp f294c00-d96a-4b04-b507-e2e3afcbee4f.ps1:12 char:1 + 启用-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation:(:) [Enable-WindowsOptionalFeature],PSInvalidOperationException + FullyQualifiedErrorId : InvalidOperation,Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand

PowerShell 以代码“1”退出。

我检查了

get-ExecutionPolicy
,这是
unrestricted
$confirmpreference
设置为
High
.

为什么我在前一天工作正常时会收到此错误?

这可能是由于 Windows 更新?我该如何解决这个问题?

powershell tfs azure-devops devops azure-pipelines
2个回答
2
投票

正如评论所说:错误消息表明您的命令之一正在尝试提示用户进行确认。如果出现

Enable-WindowsOptionalFeature
,它可能会提示重新启动。

通常您可以通过在 Powershell 命令中添加

-Force
-Confirm:$false
来抑制提示。

Additinaly,

Enable-WindowsOptionalFeature
-NoRestart
标志
,这应该防止它提示重新启动。


0
投票

就我而言,问题是由将

-debug
作为脚本参数传递给 AzurePowerShell 任务引起的。 但是错误消息不准确,它在调用命令的地方显示错误。

出现相同错误的Azure管道任务:

  - task: AzurePowerShell@5
    inputs:
      azureSubscription: '${{ parameters.serviceConnectionName }}'
      scriptType: 'FilePath'
      errorActionPreference: 'stop'
      azurePowerShellVersion: 'OtherVersion'
      preferredAzurePowerShellVersion: '9.5.0'
      scriptPath: '$(Build.SourcesDirectory)/myScript.ps1'
      ScriptArguments: >-
        -location "xxx" 
        ... 
        -debug

我的剧本:

enter image description here

在调用命令

Get-AzResourceGroup -Name 'my-rg' -Location $location
的第7行抛出错误。

删除

-debug
参数后,脚本就可以运行了。

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