AzureCLI@2 - Azure CLI v2 작업

Linux 에이전트에서 실행할 때 PowerShell Core/셸 스크립트에서 Azure 구독에 대해 Azure CLI 명령을 실행합니다. 또는 Windows 에이전트에서 실행할 때 PowerShell/PowerShell Core/일괄 처리 스크립트에서 Azure 구독에 대해 Azure CLI 명령을 실행합니다.

Linux 에이전트에서 실행할 때 PowerShell Core/셸 스크립트에서 Azure 구독에 대해 Azure CLI 명령을 실행합니다. 또는 Windows 에이전트에서 실행할 때 PowerShell/Powershell Core/batch 스크립트에서 Azure 구독에 대해 Azure CLI 명령을 실행합니다.

Syntax

# Azure CLI v2
# Run Azure CLI commands against an Azure subscription in a PowerShell Core/Shell script when running on Linux agent or PowerShell/PowerShell Core/Batch script when running on Windows agent.
- task: AzureCLI@2
  inputs:
    azureSubscription: # string. Alias: connectedServiceNameARM. Required. Azure Resource Manager connection. 
    scriptType: # 'ps' | 'pscore' | 'batch' | 'bash'. Required. Script Type. 
    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: scriptArguments. Script Arguments. 
    #powerShellErrorActionPreference: 'stop' # 'stop' | 'continue' | 'silentlyContinue'. Optional. Use when scriptType = ps || scriptType = pscore. ErrorActionPreference. Default: stop.
  # 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.
    #powerShellIgnoreLASTEXITCODE: false # boolean. Optional. Use when scriptType = ps || scriptType = pscore. Ignore $LASTEXITCODE. Default: false.
# Azure CLI v2
# Run Azure CLI commands against an Azure subscription in a PowerShell Core/Shell script when running on Linux agent or PowerShell/Powershell Core/Batch script when running on Windows agent.
- task: AzureCLI@2
  inputs:
    azureSubscription: # string. Alias: connectedServiceNameARM. Required. Azure Resource Manager connection. 
    scriptType: # 'ps' | 'pscore' | 'batch' | 'bash'. Required. Script Type. 
    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: scriptArguments. Script Arguments. 
    #powerShellErrorActionPreference: 'stop' # 'stop' | 'continue' | 'silentlyContinue'. Optional. Use when scriptType = ps || scriptType = pscore. ErrorActionPreference. Default: stop.
  # 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.
    #powerShellIgnoreLASTEXITCODE: false # boolean. Optional. Use when scriptType = ps || scriptType = pscore. Ignore $LASTEXITCODE. Default: false.

입력

azureSubscription - Azure Resource Manager 연결
입력 별칭: connectedServiceNameARM. string. 필수 요소.

배포에 대한 Azure Resource Manager 서비스 연결을 선택합니다.


scriptType - 스크립트 유형
string. 필수 요소. 허용되는 값: ps (PowerShell), pscore (PowerShell Core), batch, bash (Shell).

스크립트 유형입니다. Linux 에이전트에서 bash 실행할 때 또는 pscore 스크립트를 선택합니다. 또는 Windows 에이전트에서 batch실행할 때 , ps또는 pscore 스크립트를 선택합니다. 스크립트는 pscore 플랫폼 간 에이전트(Linux, macOS 또는 Windows)에서 실행할 수 있습니다.


scriptType - 스크립트 유형
string. 필수 요소. 허용되는 값: ps (Powershell), pscore (Powershell Core), batch, bash (Shell).

스크립트 유형입니다. Linux 에이전트에서 bash 실행할 때 또는 pscore 스크립트를 선택합니다. 또는 Windows 에이전트에서 batch실행할 때 , ps또는 pscore 스크립트를 선택합니다. 스크립트는 pscore 플랫폼 간 에이전트(Linux, macOS 또는 Windows)에서 실행할 수 있습니다.


scriptLocation - 스크립트 위치
string. 필수 요소. 허용되는 값: inlineScript (인라인 스크립트), scriptPath (스크립트 경로). 기본값은 scriptPath입니다.

스크립트의 경로입니다.


scriptPath - 스크립트 경로
string. 필요한 경우 scriptLocation = scriptPath입니다.

스크립트의 정규화된 경로입니다. .bat, 또는 .cmd Windows 기반 에이전트를 사용하는 경우 를 사용합니다.ps1. Linux 기반 에이전트 또는 기본 작업 디렉터리에 상대적인 경로를 사용하는 경우 또는 .sh 를 사용합니다.ps1.


inlineScript - 인라인 스크립트
string. 필요한 경우 scriptLocation = inlineScript입니다.

여기에서 스크립트를 인라인으로 작성할 수 있습니다. Windows 에이전트를 사용하는 경우 PowerShell, PowerShell Core 또는 일괄 처리 스크립팅을 사용합니다. Linux 기반 에이전트를 사용할 때 PowerShell Core 또는 셸 스크립팅을 사용합니다. 일괄 처리 파일의 경우 모든 Azure 명령 앞에 접두사를 call 사용합니다. 인수를 사용하여 미리 정의된 및 사용자 지정 변수를 이 스크립트에 전달할 수도 있습니다.

다음은 PowerShell/PowerShellCore/shell의 예입니다.

az --version 
az account show 

다음은 일괄 처리의 예입니다.

call  az --version 
call az account show

arguments - 스크립트 인수
입력 별칭: scriptArguments. string.

스크립트에 전달된 인수입니다.


powerShellErrorActionPreference - ErrorActionPreference
string. 선택 사항입니다. 를 사용하는 경우 scriptType = ps || scriptType = pscore를 사용합니다. 허용되는 값: stop, continue, silentlyContinue. 기본값은 stop입니다.

PowerShell/PowerShell Core 스크립트의 맨 위에 줄을 $ErrorActionPreference = 'VALUE' 추가합니다.


addSpnToEnvironment - 스크립트에서 서비스 주체 세부 정보에 액세스
boolean. 기본값은 false입니다.

스크립트의 실행 환경에 선택한 Azure 엔드포인트의 서비스 주체 ID, 서비스 주체 키 또는 워크로드 ID 페더레이션 토큰 및 테넌트 ID를 추가합니다. 스크립트에서 servicePrincipalId, servicePrincipalKey 또는 idTokentenantId 변수를 사용할 수 있습니다.

이는 Azure 엔드포인트에 서비스 주체 인증 체계 또는 워크로드 ID 페더레이션 인증 체계가 있는 경우에만 적용됩니다.

다음 목록에서는 스크립트 형식에 따라 환경 변수에 액세스하는 구문을 보여 줍니다.

  • PowerShell 스크립트 구문: $env:servicePrincipalId

  • Batch 스크립트 구문: %servicePrincipalId%

  • 셸 스크립트 구문: $servicePrincipalId


useGlobalConfig - 전역 Azure CLI 구성 사용
boolean. 기본값은 false입니다.

이 입력이 false이면 이 작업은 자체 Azure CLI 구성 디렉터리를 사용합니다. 이 작업을 사용하여 병렬 릴리스에서 Azure CLI 작업을 실행합니다.


workingDirectory - 작업 디렉터리
입력 별칭: cwd. string.

스크립트가 실행되는 현재 작업 디렉터리입니다. 비워 두면 이 입력은 리포지토리(빌드) 또는 아티팩트(릴리스)의 루트()입니다 $(System.DefaultWorkingDirectory).


failOnStandardError - 표준 오류 발생 시 실패
boolean. 기본값은 false입니다.

이 입력이 true이면 StandardError 스트림에 오류가 기록될 때 이 작업이 실패합니다. 표준 오류를 무시하고 대신 종료 코드를 사용하여 상태 확인란의 선택을 취소합니다.


powerShellIgnoreLASTEXITCODE - $LASTEXITCODE 무시
boolean. 선택 사항입니다. 를 사용하는 경우 scriptType = ps || scriptType = pscore를 사용합니다. 기본값은 false입니다.

이 입력이 false이면 스크립트 끝에 줄 if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE } 이 추가됩니다. 그러면 외부 명령의 마지막 종료 코드가 PowerShell의 종료 코드로 전파됩니다. 그렇지 않으면 스크립트의 끝에 줄이 추가되지 않습니다.


작업 제어 옵션

모든 작업에는 작업 입력 외에 제어 옵션이 있습니다. 자세한 내용은 컨트롤 옵션 및 일반적인 작업 속성을 참조하세요.

출력 변수

없음

설명

버전 작업 버전 2.0의 새로운 기능

  • PowerShell 및 PowerShell Core 스크립트에 대한 지원.
  • PowerShell Core는 플랫폼 간 에이전트(Linux, macOS 또는 Windows)에서 작동하며 에이전트에 PowerShell 버전 6 이상이 있는지 확인합니다.
  • Powershell 스크립트는 Windows 에이전트에서만 작동하며 에이전트에 PowerShell 버전 5 이하가 있는지 확인합니다.

사전 요구 사항

  • Microsoft Azure 구독.
  • Azure 계정에 대한 Azure Resource Manager 서비스 연결입니다.
  • Microsoft 호스팅 에이전트에 Azure CLI가 미리 설치되어 있어야 합니다. 하지만 프라이빗 에이전트를 사용하는 경우 빌드 및 릴리스 에이전트를 실행하는 컴퓨터에 Azure CLI를 설치합니다. 에이전트가 Azure CLI가 설치된 컴퓨터에서 이미 실행되고 있으면 모든 관련 스테이지 변수가 업데이트되도록 에이전트를 다시 시작합니다.

예제

다음 예제에서는 Azure CLI 버전을 나열하고 구독의 세부 정보를 가져옵니다.

- task: AzureCLI@2
  displayName: Azure CLI
  inputs:
    azureSubscription: <Name of the Azure Resource Manager service connection>
    scriptType: ps
    scriptLocation: inlineScript
    inlineScript: |
      az --version
      az account show

다음 예제에서는 스크립트에 인수를 전달하는 방법을 보여 줍니다.

  • 인라인 스크립트에 인수 전달:

    - task: AzureCLI@2
      inputs:
        azureSubscription: <Azure_Resource_Manager_Service_Connection>
        scriptType: 'ps'
        scriptLocation: 'inlineScript'
        arguments: '$(AZURE_STORAGE_ACCOUNT) $(AZURE_STORAGE_KEY)'
        inlineScript: './scripts/publish.ps1 $1 $2'
    
  • 스크립트 경로를 사용하여 인수 전달:

    - task: AzureCLI@2
      inputs:
        azureSubscription: <Azure_Resource_Manager_Service_Connection>
        scriptType: 'ps'
        scriptLocation: 'scriptPath'
        arguments: '$(AZURE_STORAGE_ACCOUNT) $(AZURE_STORAGE_KEY)'
        scriptPath: './scripts/publish.ps1'
    

요구 사항

요구 사항 Description
파이프라인 유형 YAML, 클래식 빌드, 클래식 릴리스
실행 중 에이전트, DeploymentGroup
요청 없음
Capabilities 이 작업은 작업의 후속 작업에 대한 요구를 충족하지 않습니다.
명령 제한 사항 모두
Settable 변수 모두
에이전트 버전 2.0.0 이상
작업 범주 배포

추가 정보