다음을 통해 공유


AzureCLI@2 - Azure CLI v2 작업

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

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

구문론

# 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.
    #visibleAzLogin: true # boolean. az login output visibility. Default: true.
# 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.

입력

Azure Resource Manager 연결
입력 별칭: connectedServiceNameARM. string; 필수 사항입니다.

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


scriptType - 스크립트 형식
string; 필수 사항입니다. 허용되는 값: ps(PowerShell), pscore(PowerShell Core), batch, bash(셸).

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


scriptType - 스크립트 형식
string; 필수 사항입니다. 허용되는 값: ps(Powershell), pscore(Powershell Core), batch, bash(셸).

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


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

스크립트의 경로입니다.


scriptPath - 스크립트 경로
string; scriptLocation = scriptPath때 필요합니다.

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


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

  • 일괄 처리 스크립트 구문: %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의 종료 코드로 전파됩니다. 그렇지 않으면 스크립트의 끝에 줄이 추가되지 않습니다.


az login output visibilityvisibleAzLogin -
boolean; 기본값은 true입니다.

true로 설정하면 az login 명령이 작업에 출력됩니다. false로 설정하면 az login 출력이 표시되지 않습니다.


작업 제어 옵션

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

출력 변수

없음.

비고

버전 작업 버전 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'
    

요구 사항

요구 사항 설명
파이프라인 유형 YAML, 클래식 빌드, 클래식 릴리스
다음에서 실행 에이전트, DeploymentGroup
요구 없음
기능 이 작업은 작업의 후속 작업에 대한 요구 사항을 충족하지 않습니다.
명령 제한 어느 것이든
settable 변수 어느 것이든
에이전트 버전 2.0.0 이상
작업 범주 배치하다

참고하십시오