使用此任务可在 Azure 环境中运行 PowerShell 脚本。 使用提供的 Azure 资源管理器服务连接对 Azure 上下文进行身份验证。
此版本的任务已弃用;使用 AzurePowerShell@5。
使用此任务可在 Azure 环境中运行 PowerShell 脚本。 使用提供的 Azure 资源管理器服务连接对 Azure 上下文进行身份验证。
语法
# Azure PowerShell v2
# Run a PowerShell script within an Azure environment.
- task: AzurePowerShell@2
inputs:
#azureConnectionType: 'ConnectedServiceNameARM' # 'ConnectedServiceName' | 'ConnectedServiceNameARM'. Alias: ConnectedServiceNameSelector. Azure Connection Type. Default: ConnectedServiceNameARM.
#azureClassicSubscription: # string. Alias: ConnectedServiceName. Required when ConnectedServiceNameSelector = ConnectedServiceName. Azure Classic Subscription.
azureSubscription: # string. Alias: ConnectedServiceNameARM. Required when ConnectedServiceNameSelector = ConnectedServiceNameARM. Azure Subscription.
ScriptType: 'FilePath' # 'FilePath' | 'InlineScript'. Required. Script Type. Default: FilePath.
#ScriptPath: # string. Optional. Use when ScriptType = FilePath. Script Path.
#Inline: # string. Optional. Use when ScriptType = InlineScript. Inline Script.
#ScriptArguments: # string. Script Arguments.
#azurePowerShellVersion: 'OtherVersion' # 'LatestVersion' | 'OtherVersion'. Alias: TargetAzurePs. Azure PowerShell Version. Default: OtherVersion.
preferredAzurePowerShellVersion: # string. Alias: CustomTargetAzurePs. Required when TargetAzurePs = OtherVersion. Preferred Azure PowerShell Version.
输入
azureConnectionType
-
Azure 连接类型
输入别名: ConnectedServiceNameSelector.
string。 允许的值:ConnectedServiceName(Azure 经典版)、ConnectedServiceNameARM(Azure 资源管理器)。 默认值:ConnectedServiceNameARM。
azureClassicSubscription
-
Azure 经典订阅
输入别名: ConnectedServiceName.
string。
ConnectedServiceNameSelector = ConnectedServiceName时是必需的。
运行 PowerShell 之前要配置的 Azure 经典订阅。
azureSubscription
-
Azure 订阅
输入别名: ConnectedServiceNameARM.
string。
ConnectedServiceNameSelector = ConnectedServiceNameARM时是必需的。
运行 PowerShell 之前要配置的 Azure 资源管理器订阅。
ScriptType
-
脚本类型
string。 必填。 允许的值:FilePath(脚本文件路径)、InlineScript(内联脚本)。 默认值:FilePath。
脚本的类型:文件路径或内联。
ScriptPath
-
脚本路径
string。 可选。 当 ScriptType = FilePath时使用。
脚本的路径。 这应该是完全限定的路径或相对于默认工作目录的路径。
Inline
-
内联脚本
string。 可选。 当 ScriptType = InlineScript时使用。 默认值:# You can write your azure powershell scripts inline here. \n# You can also pass predefined and custom variables to this script using arguments。
指定要执行的脚本。 支持的最大内联脚本长度为 5000 个字符。 如果要使用较长的脚本,请使用文件中的脚本。
ScriptArguments
-
脚本参数
string。
要传递给 PowerShell 的其他参数。 这些参数可以是序号参数,也可以是命名参数。
azurePowerShellVersion
-
Azure PowerShell 版本
输入别名: TargetAzurePs.
string。 允许的值:LatestVersion(最新版本),OtherVersion(指定其他版本)。 默认值:OtherVersion。
对于托管代理,支持的 Azure PowerShell 版本 2.1.0、3.8.0、4.2.1、5.1.1 和 6.7.0。
若要选择代理上可用的最新版本,请选择 LatestVersion(最新安装的版本)。
对于专用代理,可以使用 OtherVersion(指定其他版本)指定首选版本的 Azure PowerShell。
preferredAzurePowerShellVersion
-
首选 Azure PowerShell 版本
输入别名: CustomTargetAzurePs.
string。
TargetAzurePs = OtherVersion时是必需的。
首选的 Azure PowerShell 版本需要是适当的语义版本,例如。
1.2.3.。 不支持正则表达式(如 2.\*,2.3.\*)。 托管代理目前支持 Azure 模块版本 2.1.0、3.8.0、4.2.1、5.1.1 和 AzureRM 模块版本 2.1.0、3.8.0、4.2.1、5.1.1、6.7.0。
任务控制选项
除任务输入之外,所有任务都具有控制选项。 有关详细信息,请参阅 控件选项和常见任务属性。
输出变量
没有。