Azure DevOps Services
Note
이 기능은 이번 주와 다음 주에 출시됩니다. Azure DevOps Services 프로젝트에 아직 기능이 표시되지 않으면 며칠 후에 다시 확인하세요.
Azure DevOps CLI를 사용하면 명령줄에서 Azure DevOps 리소스를 관리할 수 있습니다. AZURECLI@3 작업을 사용하여 YAML 파이프라인에서 CLI 명령을 실행하여 CI/CD 워크플로의 일부로 일반적인 DevOps 작업을 자동화합니다. Microsoft 호스팅 Windows 및 Linux 에이전트에는 이미 Azure CLI 및 Azure DevOps CLI 확장이 포함되어 있습니다.
인증의 경우 Microsoft Entra 워크로드 ID 페더레이션에서 지원되는 Azure DevOps 서비스 연결 사용합니다. 자격 증명 관리를 제거하므로 이 방법을 사용하는 것이 좋습니다. 서비스 연결을 사용할 수 없는 경우에만 PAT(개인용 액세스 토큰)를 사용합니다.
Azure DevOps 사용하여 인증
az devops configure 및 az devops --help 같은 일부 Azure DevOps CLI 명령은 인증이 필요하지 않습니다. 그들은 Azure DevOps 연결하지 않습니다. 대부분의 명령은 Azure DevOps 상호 작용하며 인증이 필요합니다.
다음 예제와 같이 실행 중인 파이프라인에서 사용하는 System.AccessToken 보안 토큰을 사용하여 환경 변수 AZURE_DEVOPS_EXT_PAT에 할당하여 인증할 수 있습니다.
사용 System.AccessToken은 PAT가 필요합니다. 보다 안전한 대안으로 서비스 연결을 사용합니다. 설치 지침은 서비스 연결 관리를 참조하세요.
- bash: |
az pipelines build list --organization '$(System.TeamFoundationCollectionUri)' --project '$(System.TeamProject)'
displayName: 'Show build list'
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
인증이 필요한 단계가 여러 개 있는 경우 각 단계에 환경 변수를 추가 AZURE_DEVOPS_EXT_PAT 합니다.
실행 중인 파이프라인에서 사용하는 보안 토큰의 범위에 대한 자세한 내용은 Access 리포지토리, 아티팩트 및 기타 리소스를 참조하세요.
PAT(개인 액세스 토큰)를 사용하는 인증에 대한 자세한 내용은 개인 액세스 토큰으로 로그인을 참조하세요.
Windows 및 Linux 호스팅 에이전트를 사용하여 Azure DevOps CLI에 로그인
Microsoft 호스팅 Windows 및 Linux 에이전트는 Azure CLI 및 Azure DevOps CLI 확장으로 미리 구성됩니다.
다음 예제에서는 Azure DevOps 로그인하고 몇 가지 명령을 실행하는 방법을 보여 줍니다. 이 예제에서는 ubuntu-latest Microsoft 호스팅된 에이전트 이미지를 사용합니다. 다른 Windows 또는 Linux 호스팅 이미지로 바꿀 수 있습니다.
이 예제에서는 Azure DevOps CLI를 사용하여 인증합니다. 실행 중인 파이프라인에서 사용하는 System.AccessToken 보안 토큰을 사용합니다.
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- bash: az --version
displayName: 'Show Azure CLI version'
- bash: az devops configure --defaults organization='$(System.TeamFoundationCollectionUri)' project='$(System.TeamProject)' --use-git-aliases true
displayName: 'Set default Azure DevOps organization and project'
- bash: |
az pipelines build list
git pr list
displayName: 'Show build list and PRs'
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
macOS 호스팅 에이전트를 사용하여 Azure DevOps CLI 확장 설치
macOS Microsoft 호스팅 에이전트는 Azure CLI 설치되었지만 Azure DevOps CLI 확장은 설치되지 않았습니다. Azure DevOps CLI 확장을 설치하려면 Azure DevOps CLI를 호출하기 전에 파이프라인에서 다음 명령을 실행합니다.
# Install Azure DevOps extension
- bash: az extension add -n azure-devops
displayName: 'Install Azure DevOps extension'
호스트된 에이전트 Azure CLI 버전 업그레이드
Microsoft 호스팅 에이전트는 전형적으로 가상 환경의 소프트웨어에 주간 업데이트 배포합니다. 일부 도구의 경우 배포 당시의 최신 버전이 사용됩니다. 다른 경우에는 도구가 특정 버전에 고정됩니다.
- Microsoft 호스팅 에이전트의 포함된 소프트웨어와 해당 버전을 확인하려면, 설치된 Azure CLI 및 Azure DevOps CLI 확장 버전을 포함하여, 소프트웨어 테이블의 포함된 소프트웨어 링크를 따르십시오.
- 현재 버전의 Azure CLI 확인하려면
Azure CLI 참조하세요.
파이프라인에서 다음 명령을 실행하여 호스트된 이미지의 Azure CLI 업그레이드할 수 있습니다.
# Specify python version
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
architecture: 'x64'
# Update to latest Azure CLI version
- bash: pip install --pre azure-cli
displayName: 'Upgrade Azure CLI'
조건부로 Azure DevOps CLI 확장 설치
파이프라인이 Microsoft 호스팅된 여러 가상 머신 이미지에서 실행되는 경우, 그 중 일부는 Azure DevOps CLI 확장이 설치되어 있지 않은 경우 조건부로 설치할 수 있습니다.
trigger:
- main
# Run on multiple Microsoft-hosted agent images
strategy:
matrix:
linux24:
imageName: "ubuntu-24.04"
linux22:
imageName: "ubuntu-22.04"
mac15:
imageName: "macos-15"
mac14:
imageName: "macos-14"
windows2025:
imageName: "windows-2025"
maxParallel: 3
pool:
vmImage: $(imageName)
steps:
- bash: az --version
displayName: 'Show Azure CLI version'
# Install Azure DevOps CLI extension only on macOS images
- bash: az extension add -n azure-devops
condition: contains(variables.imageName, 'mac')
displayName: 'Install Azure DevOps extension'
# Azure DevOps CLI extension call that does not require login or credentials
# since it configures the local environment
- bash: az devops configure --defaults organization='$(System.TeamFoundationCollectionUri)' project='$(System.TeamProject)' --use-git-aliases true
displayName: 'Set default Azure DevOps organization and project'
# Call that does require credentials, use the System.AccessToken PAT
# and assign to AZURE_DEVOPS_EXT_PAT which is known to Azure DevOps CLI extension
- bash: |
az pipelines build list
git pr list
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
displayName: 'Show build list and PRs'
Azure DevOps CLI에서 자체 호스팅 에이전트 사용
다음 방법을 사용하여 자체 호스팅 에이전트에서 Azure DevOps CLI를 설치하거나 업그레이드할 수 있습니다.
수동으로 Azure CLI 및 Azure DevOps CLI 확장 설치
에이전트에 대한 가상 머신 이미지를 프로비전할 때 자체 호스팅 에이전트에 Azure CLI 및 Azure DevOps CLI 확장을 설치하는 것이 파이프라인을 실행할 때마다 설치하는 것보다 빠릅니다.
자체 호스팅 에이전트 이미지에 Azure CLI 설치하려면
Azure CLI 설치한 후 Azure DevOps CLI 확장 설치합니다.
파이프라인에 Azure CLI 및 Azure DevOps CLI 확장 설치
파이프라인을 사용하여 자체 호스팅 에이전트에서 Azure CLI 및 Azure DevOps CLI 확장을 구성하는 다음 예제에는 다음과 같은 필수 구성 요소가 있습니다.
- Python 사용하여 Azure CLI 설치합니다. Python Python 버전 작업의 지침에 따라 에이전트에 설치해야 합니다. 이 작업을 사용하도록 자체 호스팅 에이전트를 구성하려면 어떻게 해야 하나요?.
UsePythonVersion@0작업은 자체 호스팅 에이전트에 Python 설치하지 않습니다. 자체 호스팅 에이전트에 Python 버전이 하나만 설치되어 있고 경로에 있는 경우UsePythonVersion@0작업을 사용할 필요가 없습니다.
# Specify python version if you have side-by-side versions
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
architecture: 'x64'
# Update pip to latest
- bash: python -m pip install --upgrade pip
displayName: 'Upgrade pip'
# Update to latest Azure CLI version, min version required for Azure DevOps is 2.10.1
- bash: pip install --pre azure-cli
displayName: 'Upgrade Azure CLI'
Azure CLI DevOps 확장을 설치합니다.
# Install Azure DevOps extension
- bash: az extension add -n azure-devops
displayName: 'Install Azure DevOps extension'
# Now you can make calls into Azure DevOps CLI
# ...
다음 예제에서는 Azure CLI 설치한 다음 Azure DevOps CLI 확장을 설치합니다.
steps:
# Specify python version if you have side-by-side versions
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
architecture: 'x64'
# Update pip to latest
- bash: python -m pip install --upgrade pip
displayName: 'Upgrade pip'
# Update to latest Azure CLI version, min version required for Azure DevOps is 2.10.1
- bash: pip install --pre azure-cli
displayName: 'Upgrade Azure CLI'
# Install Azure DevOps extension
- bash: az extension add -n azure-devops
displayName: 'Install Azure DevOps extension'
# Now you can make calls into Azure DevOps CLI
# ...
변수에 Azure DevOps CLI 호출의 결과 할당
파이프라인 변수에 대한 Azure DevOps CLI 호출 결과를 저장하려면 task.setvariable 설명된 구문을 사용합니다. 다음 예제에서는 Fabrikam-2023 이라는 변수 그룹의 ID를 가져오고 이후 단계에서 이 값을 사용합니다.
variables:
- name: variableGroupId
trigger: none
pool:
vmImage: "ubuntu-latest"
steps:
- bash: az devops configure --defaults organization='$(System.TeamFoundationCollectionUri)' project='$(System.TeamProject)' --use-git-aliases true
displayName: 'Set default Azure DevOps organization and project'
- bash: echo "##vso[task.setvariable variable=variableGroupId]$(az pipelines variable-group list --group-name Fabrikam-2023 --query [].id -o tsv)"
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
displayName: 'Get Fabrikam-2023 variable group id'
- bash: az pipelines variable-group variable list --group-id '$(variableGroupId)'
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
displayName: 'List variables in Fabrikam-2023 variable group'
서비스 연결을 사용하여 인증
서비스 연결을 사용하는 경우 서비스 연결은 파이프라인에서 수동 자격 증명 관리를 요구하지 않고도 AzureCLI@3 태스크에서 Azure CLI 및 Azure DevOps CLI 명령에 필요한 자격 증명을 제공합니다.
Note
AzureCLI@3 인증에 서비스 연결을 사용하는 경우 Azure DevOps 조직에 수동으로 서비스 주체를 추가해야 합니다.
PAT가 없는 지침 및 서비스 연결 모범 사례는 서비스 연결 관리를 참조하세요.
이 코드 샘플은 기존 서비스 연결의 이름을 사용하여 새 매개 변수 serviceConnection를 정의합니다. 해당 매개 변수는 AzureCLI@3 작업에서 참조되고 있습니다. 스크립트는 비밀 없는 연결을 사용하여 REST 엔드포인트를 호출한 다음 프로젝트 및 풀을 나열합니다.
trigger:
- main
parameters:
- name: serviceConnection
displayName: Azure DevOps Service Connection Name
type: string
default: my-service-connection
steps:
- task: AzureCLI@3
displayName: Secret-less
inputs:
connectionType: 'azureDevOps'
azureDevOpsServiceConnection: '${{ parameters.serviceConnection }}'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
az rest --method get `
--url "https://status.dev.azure.com/_apis/status/health?api-version=7.1-preview.1" `
--resource 499b84ac-1321-427f-aa17-267ca6975798 `
--query "sort_by(services[?id=='Pipelines'].geographies | [], &name)" `
-o table
az devops configure -l
az devops project list --query "value[].{Name:name, Id:id}" `
-o table
az pipelines pool list --query "[].{Id:id, Name:name}" `
-o table
failOnStandardError: true
변수에 Azure DevOps CLI 호출의 결과 할당
파이프라인 변수에 대한 Azure DevOps CLI 호출 결과를 저장하려면 task.setvariable 설명된 구문을 사용합니다. 다음 예제에서는 kubernetes 라는 변수 그룹의 ID를 가져오고 이후 단계에서 이 값을 사용합니다.
trigger:
- main
variables:
- name: variableGroupId
parameters:
- name: serviceConnection
displayName: Azure DevOps Service Connection Name
type: string
default: my-service-connection
steps:
- task: AzureCLI@3
displayName: Set variable group ID
inputs:
connectionType: 'azureDevOps'
azureDevOpsServiceConnection: '${{ parameters.serviceConnection }}'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
az devops configure -l
$id = az pipelines variable-group list --group-name kubernetes --query [].id -o tsv
Write-Host "##vso[task.setvariable variable=variableGroupId]$id"
- task: AzureCLI@3
displayName: List variable group variables
inputs:
connectionType: 'azureDevOps'
azureDevOpsServiceConnection: '${{ parameters.serviceConnection }}'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
az pipelines variable-group variable list --group-id '$(variableGroupId)'
작업 및 단계에서 변수 작업을 포함하여 변수를 사용하는 더 많은 예제는 변수 정의를 참조하세요. 이전 예제에서 사용된 쿼리 구문의 예는 JMESPath 쿼리를 사용하여 Azure CLI 명령 출력을 쿼리하는 방법 참조하세요.