AzurePowerShell@5 - v5 작업 Azure PowerShell

이 작업을 사용하여 Azure 환경 내에서 PowerShell 스크립트를 실행합니다. Azure 컨텍스트는 제공된 Azure Resource Manager 서비스 연결로 인증됩니다.

참고

기본적으로 Azure PowerShell v5는 Linux 에이전트용 PowerShell Core를 사용하고 Windows 에이전트에는 Windows PowerShell 사용합니다. Windows 에이전트에서 최신 버전의 PowerShell을 사용하려면 매개 변수를 pwshtrue설정합니다. 그러면 PowerShell Core가 대신 사용됩니다.

Syntax

# Azure PowerShell v5
# Run a PowerShell script within an Azure environment.
- task: AzurePowerShell@5
  inputs:
    azureSubscription: # string. Alias: ConnectedServiceNameARM. Required. Azure Subscription. 
    #ScriptType: 'FilePath' # 'FilePath' | 'InlineScript'. Script Type. Default: FilePath.
    #ScriptPath: # string. Optional. Use when ScriptType = FilePath. Script Path. 
    #Inline: # string. Optional. Use when ScriptType = InlineScript. Inline Script. 
    #ScriptArguments: # string. Optional. Use when ScriptType = FilePath. Script Arguments. 
    #errorActionPreference: 'stop' # 'stop' | 'continue' | 'silentlyContinue'. ErrorActionPreference. Default: stop.
    #FailOnStandardError: false # boolean. Fail on Standard Error. Default: false.
  # Azure PowerShell version options
    #azurePowerShellVersion: 'OtherVersion' # 'LatestVersion' | 'OtherVersion'. Alias: TargetAzurePs. Azure PowerShell Version. Default: OtherVersion.
    preferredAzurePowerShellVersion: # string. Alias: CustomTargetAzurePs. Required when TargetAzurePs = OtherVersion. Preferred Azure PowerShell Version. 
  # Advanced
    #pwsh: false # boolean. Use PowerShell Core. Default: false.
    #validateScriptSignature: false # boolean. Optional. Use when ScriptType = FilePath. Validate script signature. Default: false.
    #workingDirectory: # string. Working Directory.
# Azure PowerShell v5
# Run a PowerShell script within an Azure environment.
- task: AzurePowerShell@5
  inputs:
    azureSubscription: # string. Alias: ConnectedServiceNameARM. Required. Azure Subscription. 
    #ScriptType: 'FilePath' # 'FilePath' | 'InlineScript'. Script Type. Default: FilePath.
    #ScriptPath: # string. Optional. Use when ScriptType = FilePath. Script Path. 
    #Inline: # string. Optional. Use when ScriptType = InlineScript. Inline Script. 
    #ScriptArguments: # string. Optional. Use when ScriptType = FilePath. Script Arguments. 
    #errorActionPreference: 'stop' # 'stop' | 'continue' | 'silentlyContinue'. ErrorActionPreference. Default: stop.
    #FailOnStandardError: false # boolean. Fail on Standard Error. Default: false.
  # Azure PowerShell version options
    #azurePowerShellVersion: 'OtherVersion' # 'LatestVersion' | 'OtherVersion'. Alias: TargetAzurePs. Azure PowerShell Version. Default: OtherVersion.
    preferredAzurePowerShellVersion: # string. Alias: CustomTargetAzurePs. Required when TargetAzurePs = OtherVersion. Preferred Azure PowerShell Version. 
  # Advanced
    #pwsh: false # boolean. Use PowerShell Core. Default: false.
    #workingDirectory: # string. Working Directory.

입력

azureSubscription - Azure 구독
입력 별칭: ConnectedServiceNameARM. string. 필수 요소.

PowerShell을 실행하기 전에 구성할 Azure Resource Manager 구독입니다.


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. 선택 사항입니다. 를 사용하는 경우 ScriptType = FilePath를 사용합니다.

PowerShell에 전달할 추가 매개 변수입니다. 이러한 매개 변수는 서수 또는 명명된 매개 변수일 수 있습니다. 인라인 스크립트 옵션에는 적용되지 않습니다.


errorActionPreference - ErrorActionPreference
string. 허용되는 값: stop, continue, silentlyContinue. 기본값은 stop입니다.

스크립트를 실행하기 위한 변수 값을 ErrorActionPreference 선택합니다.


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

이 경우 오류가 오류 파이프라인에 기록되거나 표준 오류 스트림에 데이터가 기록되는 경우 이 작업이 실패합니다.


azurePowerShellVersion - Azure PowerShell 버전
입력 별칭: TargetAzurePs. string. 허용되는 값: LatestVersion (최신 설치된 버전), OtherVersion (다른 버전 지정). 기본값은 OtherVersion입니다.

호스트된 에이전트의 경우 지원되는 Azure PowerShell 버전은 , 1.6.0, 2.3.23.1.02.6.0(호스트된 VS2017 큐)입니다1.0.0. 에이전트에서 사용 가능한 최신 버전을 선택하려면 (설치된 최신 버전)을 선택합니다 LatestVersion .

프라이빗 에이전트의 경우 를 사용하여 OtherVersion 기본 버전의 Azure PowerShell 지정할 수 있습니다(다른 버전 지정).


preferredAzurePowerShellVersion - 기본 Azure PowerShell 버전
입력 별칭: CustomTargetAzurePs. string. 필요한 경우 TargetAzurePs = OtherVersion입니다.

기본 Azure PowerShell 버전은 적절한 의미 체계 버전이어야 합니다. 1.2.3. 와 같은 2.\*,2.3.\* Regex는 지원되지 않습니다. 호스트된 VS2017 풀은 현재 Az 모듈 버전 1.0.0, , 1.6.02.3.2, 2.6.0및 을 3.1.0지원합니다.


pwsh - PowerShell Core 사용
boolean. 기본값은 false입니다.

이 경우 Windows 에이전트에서 실행되는 작업은 대신 powershell.exe경로에서 를 사용합니다pwsh.exe.


validateScriptSignature - 스크립트 서명 유효성 검사
boolean. 선택 사항입니다. 를 사용하는 경우 ScriptType = FilePath를 사용합니다. 기본값은 false입니다.

이 경우 태스크는 먼저 검사 실행하기 전에 지정된 스크립트가 서명되고 유효한지 확인합니다.


workingDirectory - 작업 디렉터리
string.

스크립트가 실행되는 작업 디렉터리입니다.


작업 제어 옵션

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

출력 변수

없음

설명

문제 해결

스크립트가 로컬로 작동했지만 파이프라인에서 실패했습니다.

일반적으로 파이프라인에 사용된 서비스 연결에 스크립트를 실행할 수 있는 권한이 부족한 경우에 발생합니다. 로컬에서 스크립트는 자격 증명으로 실행되며 필요한 액세스 권한이 있을 수 있으므로 성공합니다.

이 문제를 resolve 서비스 주체/인증 자격 증명에 필요한 권한이 있는지 확인합니다. 자세한 내용은 Role-Based Access Control 사용하여 Azure 구독 리소스에 대한 액세스 관리를 참조하세요.

오류: 버전<: 'version>'이 있는 '<모듈 이름>' 모듈을 찾을 수 없습니다. 모듈이 최근에 설치된 경우 Azure Pipelines 작업 에이전트를 다시 시작한 후 다시 시도합니다.

Azure PowerShell 작업은 Azure/AzureRM/Az PowerShell 모듈을 사용하여 Azure 구독과 상호 작용합니다. 이 문제는 호스트된 에이전트에서 PowerShell 모듈을 사용할 수 없는 경우에 발생합니다. 따라서 특정 작업 버전의 경우 사용 가능한 버전 목록의 Azure PowerShell 버전 옵션에 기본 Azure PowerShell 버전을 지정해야 합니다. 설치된 소프트웨어는 Microsoft 호스팅 에이전트소프트웨어 테이블에서 찾을 수 있습니다.

서비스 연결 문제

서비스 연결과 관련된 문제를 해결하려면 서비스 연결 문제 해결을 참조하세요.

예제

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

- task: AzurePowerShell@5
  inputs:
    azureSubscription: my-arm-service-connection
    scriptType: filePath
    scriptPath: $(Build.SourcesDirectory)\myscript.ps1
    scriptArguments:
      -Arg1 val1 `
      -Arg2 val2 `
      -Arg3 val3
    azurePowerShellVersion: latestVersion
    pwsh: true

다음 인수는 인라인 스크립트를 호출하는 방법을 보여줍니다.

- task: AzurePowerShell@5
  inputs:
    azureSubscription: 'Azure subscription connection placeholder'
    azurePowerShellVersion: LatestVersion
    ScriptType: 'InlineScript'
    Inline: |
      # You can write your azure powershell scripts inline here. 
      # You can also pass predefined and custom variables to this script using arguments
      Write-Host 'Hello'
      Write-Host 'World!'

요구 사항

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