Azure Pipelines
이 문서는 Azure Pipelines용 azure-pipelines 트리거를 설명합니다. 주어진 에이전트 풀(agent pool)에 대기 중인 파이프라인 실행 수에 따라 스케일링합니다.
출처: 문서
본문
트리거 사양 (Trigger Specification)
이 사양은 Azure Pipelines용 azure-pipelines 트리거를 설명합니다. 주어진 에이전트 풀에 대기 중인 파이프라인 실행 수에 따라 스케일링합니다.
triggers:
- type: azure-pipelines
metadata:
# Optional: Name of the pool in Azure DevOps
poolName: "{agentPoolName}"
# Optional: Learn more in 'How to determine your pool ID'
poolID: "{agentPoolId}"
# Optional: Azure DevOps organization URL, can use TriggerAuthentication as well
organizationURLFromEnv: "AZP_URL"
# Optional: Azure DevOps Personal Access Token, can use TriggerAuthentication as well
personalAccessTokenFromEnv: "AZP_TOKEN"
# Optional: Target queue length
targetPipelinesQueueLength: "1" # Default 1
activationTargetPipelinesQueueLength: "5" # Default 0
# Optional: Parent template to read demands from
parent: "{parent ADO agent name}"
# Optional: Demands string to read demands from ScaledObject
demands: "{demands}"
# Optional: Demands of jobs must exactly match the capabilities the trigger defines
requireAllDemands: false
# Optional: Require jobs to include specified demands, ignoring any extra ones
requireAllDemandsAndIgnoreOthers: false
# Optional: How many jobs to fetch for the pool in the API (default: 250)
jobsToFetch: "{jobsToFetch}"
# Optional: Whether to only fetch unfinished jobs from the API (default: false)
fetchUnfinishedJobsOnly: false
# Optional: Whether to include jobs already assigned to an agent when calculating queue length (default: true)
scaleOnInFlight: true
# Optional: Property to enable case-insensitive comparison of pipeline job demands (default: false)
caseInsensitiveDemandsProcessing: false
authenticationRef:
name: pipeline-trigger-auth
매개변수 목록:
-
poolName - 풀의 이름입니다. (선택, poolID 또는 poolName 중 하나는 구성해야 합니다)
-
poolID - 풀의 ID입니다. (선택, poolID 또는 poolName 중 하나는 구성해야 합니다)
-
organizationURLFromEnv - 배포가 Azure DevOps 조직의 URL을 가져오는 데 사용하는 환경 변수의 이름입니다.
-
personalAccessTokenFromEnv - Azure DevOps용 개인 액세스 토큰(PAT)을 제공하는 환경 변수의 이름입니다. 만드는 방법은 공식 문서에서 자세히 알아보세요.
-
targetPipelinesQueueLength - 스케일링할 큐의 대기 중인 작업 수에 대한 대상 값입니다. (기본값: 1, 선택) - 예시: 한 파드가 10개의 작업을 처리할 수 있으면 큐 길이 대상을 10으로 설정합니다. 큐의 실제 작업 수가 30이면 스케일러는 3개 파드로 스케일링합니다.
-
activationTargetPipelinesQueueLength - 스케일러를 활성화하기 위한 대상 값입니다. 활성화에 대해 자세히 알아보세요. (기본값: 0, 선택)
-
parent - ScaledObject와 일치하는 ADO 에이전트의 이름을 넣습니다. 예를 들어 mavenagent-scaledobject는 "mavenagent-keda-template"이라는 이름의 초기 Deployment를 가질 수 있으며, 이것이 오프라인으로 만들어지는 Deployment입니다. 이 이름은 환경 변수 "AZP_NAME"으로 초기 Deployment에 제공됩니다. jobsToFetch와 상호 배타적입니다.
-
demands - ScaledObject에 제공된 demands 문자열을 넣습니다. 이것은 반드시 에이전트가 실제로 가진 capability 목록의 부분 집합이어야 합니다. 예: maven,docker
-
jobsToFetch - KEDA가 Azure Pipeline API에서 풀을 위해 가져올 작업 수입니다. parent 및 fetchUnfinishedJobsOnly와 상호 배타적입니다. (기본값: 250, 선택)
-
fetchUnfinishedJobsOnly - Azure Pipeline API에서 완료되지 않은 작업만 가져올지 여부입니다. 일반적으로 API는 완료·실행 중·대기 중 작업을 모두 반환합니다. 이 매개변수를 true로 설정하면 API 호출이 수정되어 실행 중 및 대기 중 작업만 반환되며, 반환되는 작업 수가 상당히 줄어듭니다. jobsToFetch와 상호 배타적입니다. (기본값: false, 선택)
-
scaleOnInFlight - 큐 길이를 계산할 때 이미 에이전트에 할당된 미완료 작업(ReceiveTime이 설정됨)을 포함할지 여부입니다. 완료된 작업(Result가 설정됨)은 항상 제외됩니다. (기본값: true, 선택)
-
caseInsensitiveDemandsProcessing - 파이프라인 작업 demands의 대소문자를 구분하지 않는 비교를 활성화하는 속성입니다. 이 매개변수를 true로 설정하면 demands 검사가 대소문자를 구분하지 않습니다. (기본값: false, 선택)
💡 참고: poolID 또는 poolName 중 하나를 사용할 수 있습니다. 둘 다 지정하면 poolName이 사용됩니다.
기본적으로(scaleOnInFlight: true) 큐 길이에는 할당되지 않은 작업과 이미 에이전트에 할당된 작업이 모두 포함됩니다. 이는 바쁜 에이전트를 replica 수의 일부로 간주하는 ScaledObject와, 실행 중인 작업을 스스로 빼는 기본 스케일링 전략을 가진 ScaledJob에 잘 맞습니다. 할당되지 않은 작업만 세려면 scaleOnInFlight: false로 설정하고 정확한(accurate) ScaledJob 스케일링 전략과 결합하세요. 스케일링 전략에 대해 더 알아보려면 ScaledJob 사양을 참고하세요.
인증 매개변수 (Authentication Parameters)
Azure Pipelines 스케일러는 다음과 같은 Azure DevOps 인증 방식을 지원합니다:
- 개인 액세스 토큰(PAT)
- Azure AD Workload Identity
- 클라이언트 시크릿 또는 인증서를 사용하는 Microsoft Entra 서비스 주체(service principal)
Azure DevOps 조직 URL은 organizationURL을 통해 직접 제공하거나, scale target을 통해 organizationURLFromEnv로 제공하거나, 인증 매개변수로 제공할 수 있습니다. PAT는 personalAccessTokenFromEnv 또는 authenticationRef를 통해 제공할 수 있습니다. Workload identity 및 서비스 주체 인증은 authenticationRef를 통해 구성해야 합니다.
두 개 이상의 인증 방식을 구성한 경우 KEDA는 다음 우선순위를 사용합니다:
- 개인 액세스 토큰
- Azure AD Workload Identity
- Microsoft Entra 서비스 주체
개인 액세스 토큰 인증
- organizationURL - Azure DevOps 조직의 URL입니다.
- personalAccessToken - Azure DevOps용 개인 액세스 토큰입니다.
Azure AD Workload Identity 인증
podIdentity.provider를 azure-workload로 설정한 TriggerAuthentication 또는 ClusterTriggerAuthentication을 구성하세요.
Microsoft Entra 서비스 주체 인증
재사용 가능한 azureServicePrincipal 인증 제공자를 클라이언트 시크릿 또는 클라이언트 인증서와 함께 구성하세요. Azure Pipelines 스케일러는 Azure DevOps용 Microsoft Entra 토큰을 획득해 bearer 토큰으로 보냅니다. 스케일러를 사용하기 전에 서비스 주체를 Azure DevOps 조직에 추가하고, 필요한 에이전트 풀과 해당 작업 요청을 읽을 권한을 부여하세요. Azure DevOps에 추가할 때는 애플리케이션 등록 개체 ID가 아니라 Enterprise applications의 서비스 주체 개체 ID를 사용하세요. 자세한 설정 절차는 Azure DevOps 서비스 주체 문서를 참고하세요.
풀 ID를 결정하는 방법 (How to determine your pool ID)
poolID를 얻는 방법은 여러 가지가 있습니다. 가장 쉬운 방법은 az cli를 사용해 az pipelines pool list --pool-name {agentPoolName} --organization {organizationURL} --query [0].id 명령으로 얻는 것입니다. 또한 UI를 통해 조직에서 에이전트 풀로 이동(Organization settings -> Agent pools -> {agentPoolName})해 URL에서 얻을 수도 있습니다. URL은 https://dev.azure.com/{organization}/_settings/agentpools?poolId={poolID}&view=jobs 와 비슷해야 합니다.
주의 - 이것은 프로젝트 수준이 아니라 조직 수준에서 결정해야 합니다. 그렇지 않으면 잘못된 ID를 얻을 수 있습니다.
마지막으로 https://dev.azure.com/{organizationName}/_apis/distributedtask/pools?poolname={agentPoolName} 엔드포인트를 호출한 HTTP 요청 응답의 key value[0].id에서 풀 ID를 얻을 수도 있습니다.
에이전트에서 demands 지원하기
기본적으로 에이전트 스케일러에서 demands를 사용하지 않으면 풀의 큐 길이에 따라 스케일링합니다. Demands(캐퍼빌리티)는 같은 풀 안에 서로 다른 캐퍼빌리티를 가진 여러 에이전트가 있을 때 유용합니다. 예를 들어 kube 클러스터에는 dotnet5, dotnet6, java 또는 maven을 지원하는 에이전트가 있을 수 있습니다. 특히 이들은 배타적 에이전트로, 잘못된 에이전트에서 작업이 실행되면 실패합니다. 이것이 Microsoft의 demands 기능입니다.
-
Parent 사용: Azure DevOps는 대기 중인 작업과 일치할 수 있는 에이전트를 결정할 수 있습니다. parent 템플릿을 지정하면 KEDA는 작업 요청을 추가로 조사해 parent가 작업을 충족할 수 있는지 판단합니다. parent가 작업을 완료할 수 있으면 워크로드를 스케일링해 요청을 충족합니다. 일반적으로 오프라인 상태인 parent 템플릿은 풀의 에이전트 목록에 남아 있어야 합니다.
-
demands 사용: KEDA는 제공된 demands를 기반으로 어떤 에이전트가 작업을 충족할 수 있는지 판단합니다. demands는 쉼표로 구분된 목록으로 제공되며 에이전트의 실제 캐퍼빌리티의 부분 집합이어야 합니다. (예: maven,java,make. 참고: Agent.Version은 무시됩니다).
-
requireAllDemands를 true로 설정하면 작업의 demands가 트리거의 demands와 정확히 일치해야 합니다. 즉 demands가 maven인 작업은 캐퍼빌리티가 maven,java인 에이전트와 일치하지 않습니다.
-
requireAllDemandsAndIgnoreOthers를 true로 설정하면 작업의 demands에 지정된 모든 demands가 정확히 포함되어야 하지만 추가 demands는 무시됩니다. 예를 들어 demands가 maven인 작업은 maven이 demand 목록에 있는 한 캐퍼빌리티가 maven,java인 에이전트와 일치합니다.
-
참고: requireAllDemands는 requireAllDemandsAndIgnoreOthers보다 우선합니다. 둘 다 true로 설정하면 정확히 일치하는 경우만 허용됩니다.
Microsoft 문서: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/demands?view=azure-devops&tabs=yaml
parent 템플릿 기능은 Microsoft가 아닌 KEDA에만 있는 기능이며, demands를 지원하는 또 다른 방법입니다. 에이전트 스케일러에서 demands를 사용하려면 파이프라인에 다음을 추가할 수 있습니다:
pool:
- name: "{agentPoolName}"
demands:
- example-demands
- another-demand -equals /bin/executable
그런 다음 demands 매개변수로 에이전트가 지원하는 demands를 지정하거나, parent 매개변수로 scaled object와 일치하는 템플릿을 연결할 수 있습니다. KEDA는 다음 평가 순서를 사용합니다:
- 스케일링 정의에 parent와 demands가 모두 정의되어 있지 않으면 작업을 충족하도록 워크로드를 스케일링합니다.
- parent가 설정되면 KEDA는 작업 요청을 조사해 parent가 작업을 충족할 수 있는지 판단합니다. parent가 작업을 완료할 수 있으면 요청을 충족하도록 워크로드를 스케일링합니다.
- 마지막으로 스케일링 정의에 demands가 설정되면 KEDA는 제공된 demands에 따라 어떤 에이전트가 작업을 충족할 수 있는지 판단합니다.
참고: 하나 이상의 스케일링 정의가 작업의 demands를 충족할 수 있으면 둘 다 에이전트를 하나씩 실행합니다.
내부적으로 어떻게 동작하나요 (How it works under the hood)
Azure DevOps에는 모든 작업과 작업이 할당되었거나 잠재적으로 할당될 수 있는 에이전트 목록을 반환하는 Job Request API가 있습니다. 이것은 미문서화된 Microsoft API로 https://dev.azure.com//_apis/distributedtask/pools//jobrequests 에서 사용할 수 있습니다. KEDA는 이 요청을 해석해 스케일링 정의의 parent에서 정의된 일치하는 템플릿이나, 스케일링 정의에 지정된 demands를 충족할 수 있는 에이전트를 찾습니다. 찾으면 정의와 일치하는 워크로드를 스케일링하고 Azure DevOps가 해당 에이전트에 할당합니다.
그러나 이 API는 미문서화되어 있어 다른 쿼리 매개변수로 호출할 때 고유한 특이점이 있습니다. 예를 들어 $top 쿼리 매개변수를 주면 반환되는 JSON 형식이 변경되어 스케일러가 일치하는 에이전트를 더 이상 찾을 수 없게 됩니다. 따라서 트리거 메타데이터의 parent 속성과 함께 사용할 수 없습니다. 그래서 jobsToFetch는 트리거 메타데이터에서 parent와 상호 배타적으로 만듭니다. 또한 $top 쿼리 매개변수는 completedRequestCount 같은 다른 매개변수보다 우선합니다. $top 쿼리 매개변수를 주면 completedRequestCount=0을 줘도 완료된 작업이 응답에 포함됩니다. completedRequestCount=0은 대기 중 및 실행 중 작업만 반환되어야 함을 나타내는 값이지만요. 따라서 jobsToFetch는 트리거 메타데이터에서 fetchUnfinishedJobsOnly와도 상호 배타적입니다.
에이전트 컨테이너 구성 (Configuring the agent container)
Microsoft self-hosted docker agent 문서: https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops#linux
에이전트 컨테이너의 entrypoint로 Step 5의 스크립트를 사용하세요. 작업이 완료되면 에이전트가 종료되고 스스로 정리되도록 --once 스위치를 사용해 셸 스크립트의 이 섹션을 변경해야 합니다. 정리용 if 문은 자동 배포 parent 템플릿 방식을 사용하는 경우에만 필요합니다.
print_header "4. Running Azure Pipelines agent..."
trap 'cleanup; exit 0' EXIT
trap 'cleanup; exit 130' INT
trap 'cleanup; exit 143' TERM
chmod +x ./run-docker.sh
# To be aware of TERM and INT signals call run.sh
# Running it with the --once flag at the end will shut down the agent after the build is executed
./run-docker.sh "$@" & wait $!
을(를)
print_header "4. Running Azure Pipelines agent..."
if ! grep -q "template" <<< "$AZP_AGENT_NAME"; then
echo "Cleanup Traps Enabled"
trap 'cleanup; exit 0' EXIT
trap 'cleanup; exit 130' INT
trap 'cleanup; exit 143' TERM
fi
chmod +x ./run-docker.sh
# To be aware of TERM and INT signals call run.sh
# Running it with the --once flag at the end will shut down the agent after the build is executed
./run-docker.sh "$@" --once & wait $!
으로 변경합니다.
개인 액세스 토큰 인증 예시 (Example using Personal Access Token authentication)
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: pipeline-auth
data:
personalAccessToken: <encoded personalAccessToken>
---
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: pipeline-trigger-auth
namespace: default
spec:
secretTargetRef:
- parameter: personalAccessToken
name: pipeline-auth
key: personalAccessToken
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: azure-pipelines-scaledobject
namespace: default
spec:
scaleTargetRef:
name: azdevops-deployment
minReplicaCount: 1
maxReplicaCount: 5
triggers:
- type: azure-pipelines
metadata:
poolID: "1"
organizationURLFromEnv: "AZP_URL"
parent: "example-keda-template"
demands: "maven,docker"
authenticationRef:
name: pipeline-trigger-auth
서비스 주체 인증 예시 (Example using service principal authentication)
다음 예시는 클라이언트 시크릿을 사용합니다. 인증서 자격 증명은 같은 azureServicePrincipal 인증 제공자로 구성할 수 있습니다.
apiVersion: v1
kind: Secret
metadata:
name: azure-pipelines-service-principal
namespace: default
type: Opaque
data:
clientSecret: <base64-encoded-client-secret>
---
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: azure-pipelines-service-principal
namespace: default
spec:
azureServicePrincipal:
tenantId: <tenant-id>
clientId: <client-id>
clientSecret:
valueFrom:
secretKeyRef:
name: azure-pipelines-service-principal
key: clientSecret
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: azure-pipelines-scaledobject
namespace: default
spec:
scaleTargetRef:
name: azdevops-deployment
minReplicaCount: 1
maxReplicaCount: 5
triggers:
- type: azure-pipelines
metadata:
poolID: "1"
organizationURL: "https://dev.azure.com/<organization>"
authenticationRef:
name: azure-pipelines-service-principal
Parent Deployment 또는 StatefulSet 예시 (Example for Parent Deployment or StatefulSet)
apiVersion: apps/v1
kind: Deployment
metadata:
name: agent
spec:
replicas: 1
selector:
matchLabels:
app: agent
spec:
containers:
- name: agent
image: [SAME AS SCALED JOB]
envFrom:
- secretRef:
name: ado-pat-tokens
env:
- name: AZP_AGENT_NAME
value: example-keda-template # Matches Scaled Job Parent
pod identity 인증 사용 예시 (Example for using pod identity authentication)
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: pipeline-trigger-auth
spec:
podIdentity:
provider: azure-workload
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: azure-pipelines-scaledobject
namespace: default
spec:
scaleTargetRef:
name: azdevops-deployment
minReplicaCount: 1
maxReplicaCount: 5
triggers:
- type: azure-pipelines
metadata:
poolID: "1"
organizationURLFromEnv: "AZP_URL"
parent: "example-keda-template"
demands: "maven,docker"
authenticationRef:
name: pipeline-trigger-auth
더 알아보기 (Learn more)
Azure Pipelines 스케일러를 사용하면 에이전트 풀에 쌓이는 파이프라인 작업을 효율적으로 처리하는 에이전트 파드를 자동으로 확장·축소할 수 있어요. 공식 문서를 참고해 여러 인증 방식과 demands 설정을 직접 실습해 보시길 바랍니다.