AzureCLI@1 - Azure CLI v1 工作

在 Linux 代理程式上執行時,針對殼層腳本中的 Azure 訂用帳戶執行 Azure CLI 命令,或在 Windows 代理程式上執行時執行批次腳本。

對 Azure 訂用帳戶使用 Azure CLI 命令執行殼層或批次腳本。

Syntax

# 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.
# Azure CLI v1
# Run a Shell or Batch script with Azure CLI commands against an azure subscription.
- 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
    #workingDirectory: # string. Alias: cwd. Working Directory. 
    #failOnStandardError: false # boolean. Fail on Standard Error. Default: false.

輸入

azureSubscription - Azure 訂用帳戶
輸入別名: connectedServiceNameARMstring. 必要。

選取部署的 Azure Resource Manager 訂用帳戶。


scriptLocation - 腳本位置
string. 必要。 允許的值: inlineScript (內嵌腳稿) , scriptPath (腳稿路徑) 。 預設值:scriptPath

選取腳本位置。


scriptPath - 腳本路徑
string. 當 scriptLocation = scriptPath 時為必要。

文本的完整路徑或相對於預設工作目錄的路徑。


inlineScript - 內嵌腳本
string. 當 scriptLocation = inlineScript 時為必要。

您可以在這裏內嵌撰寫文稿。 使用 Windows 代理程式時,請使用批次腳本。 使用以Linux為基礎的代理程式時,請使用殼層腳本。 對於批處理檔,請在每個 Azure 命令之前使用前置詞 call 。 您也可以使用自變數將預先定義和自訂變數傳遞至此腳本

請參閱以下範例。 第一個是殼層範例,第二個是批次範例:

azure --version || azure account show 
call  azure --version || call azure account show

arguments - 參數
輸入別名: argsstring.

傳遞至腳本的自變數。


addSpnToEnvironment - 存取文本中的服務主體詳細數據
boolean. 預設值:false

將您選擇的 Azure 端點的服務主體識別碼和金鑰新增至腳本的執行環境。 您可以在文稿中使用 $servicePrincipalId$servicePrincipalKey 變數。

僅在 Azure 端點具有服務主體驗證配置時,才會接受此作業。


useGlobalConfig - 使用全域 Azure CLI 設定
boolean. 預設值:false

如果這是 false,此工作將會使用自己的個別 Azure CLI 組態目錄。 這可用來以 平行 版本執行 Azure CLI 工作。


workingDirectory - 工作目錄
輸入別名: cwdstring.

執行文稿的目前工作目錄。 如果保留空白,則此輸入是 (組建) 或成品 (發行) 的根目錄,也就是 $(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 Resource Manager (ARM) 訂用帳戶。

規格需求

需求 描述
管線類型 YAML、傳統組建、傳統版本
執行於 Agent、DeploymentGroup
要求
Capabilities 此工作不符合作業中後續工作的任何需求。
命令限制 任何
Settable 變數 任何
代理程式版本 2.0.0 或更新版本
工作類別 部署