在 Linux 代理上运行时,在 Shell 脚本中针对 Azure 订阅运行 Azure CLI 命令,或者在 Windows 代理上运行批处理脚本时运行。
语法
# Azure CLI v1
# Run Azure CLI commands against an Azure subscription in a Shell script when running on Linux agent or Batch script when running on Windows agent.
- task: AzureCLI@1
inputs:
azureSubscription: # string. Alias: connectedServiceNameARM. Required. Azure subscription.
scriptLocation: 'scriptPath' # 'inlineScript' | 'scriptPath'. Required. Script Location. Default: scriptPath.
scriptPath: # string. Required when scriptLocation = scriptPath. Script Path.
#inlineScript: # string. Required when scriptLocation = inlineScript. Inline Script.
#arguments: # string. Alias: args. Arguments.
# Advanced
#addSpnToEnvironment: false # boolean. Access service principal details in script. Default: false.
#useGlobalConfig: false # boolean. Use global Azure CLI configuration. Default: false.
#workingDirectory: # string. Alias: cwd. Working Directory.
#failOnStandardError: false # boolean. Fail on Standard Error. Default: false.
输入
scriptLocation
-
脚本位置
string
。 必填。 允许的值:inlineScript
(内联脚本)、scriptPath
(脚本路径)。 默认值:scriptPath
。
选择脚本位置。
scriptPath
-
脚本路径
string
。
scriptLocation = scriptPath
时是必需的。
脚本的完全限定路径或相对于默认工作目录的路径。
inlineScript
-
内联脚本
string
。
scriptLocation = inlineScript
时是必需的。
可以在此处内联编写脚本。 使用 Windows 代理时,请使用批处理脚本。 使用基于 Linux 的代理时,请使用 shell 脚本。 对于批处理文件,请在每个 Azure 命令之前使用前缀 call
。 还可以使用参数将预定义变量和自定义变量传递给此脚本
请参阅以下示例。 第一个是 shell 示例,第二个是批处理示例:
azure --version || azure account show
call azure --version || call azure account show
在脚本中 addSpnToEnvironment
- 访问服务主体详细信息
boolean
。 默认值:false
。
将所选的 Azure 终结点的服务主体 ID 和密钥添加到脚本的执行环境。 可以在脚本中使用 $servicePrincipalId
和 $servicePrincipalKey
变量。
仅在 Azure 终结点具有服务主体身份验证方案时才可执行此操作。
useGlobalConfig
-
使用全局 Azure CLI 配置
boolean
。 默认值:false
。
如果为 false,此任务将使用其自己的单独 Azure CLI 配置目录。 这可用于在 并行 版本中运行 Azure CLI 任务。
workingDirectory
-
工作目录
输入别名: cwd
.
string
。
运行脚本的当前工作目录。 如果留空,则此输入是存储库(生成)或项目(release)的根,即 $(System.DefaultWorkingDirectory)
。
标准错误failOnStandardError
- 失败
boolean
。 默认值:false
。
如果此输入为 true,则当任何错误写入 StandardError 流时,此任务将失败。 清除复选框以忽略标准错误,而是依赖于退出代码来确定状态。
任务控制选项
除任务输入之外,所有任务都具有控制选项。 有关详细信息,请参阅 控件选项和常见任务属性。
输出变量
没有。
注解
版本 1.0 中的新增功能:
- 支持基于 Python 的新 Azure CLI 2.0
- 适用于跨平台代理(Linux、macOS 或 Windows)
- 若要使用 Azure CLI 1.0(基于node.js),请切换到任务版本 0.0
- 限制:- 不支持 Azure 经典订阅。 Azure CLI 2.0 仅支持 Azure 资源管理器(ARM)订阅。