Step 1: Understand the Requirements
You need to create a self-hosted agent for Azure Pipelines.
It will be hosted in a pod (for example, in Kubernetes).
All pipelines in Project1 should be able to use this agent pool named Pool1.
Step 2: Create the Agent Pool in Azure DevOps
Go to your Azure DevOps organization:https://dev.azure.com/{YourOrganizationName}
In the bottom-left corner, click on the Organization settings gear icon.
In the left menu, click on Agent pools.
Click on Add pool.
Provide the following:
Pool name: Pool1
Pool type: Self-hosted
Grant access permission to all pipelines: Checked (so that all Project1 pipelines can use this pool)
Click Create.
Now you have an empty agent pool named Pool1.
Step 3: Prepare the Self-hosted Agent as a Pod
You need to deploy an Azure Pipelines agent container as a pod. Here’s how to do it:
Option 1: Using Kubernetes directly (YAML deployment)
apiVersion: apps/v1
kind: Deployment
metadata:
name: azure-pipelines-agent
labels:
app: azure-pipelines-agent
spec:
replicas: 1
selector:
matchLabels:
app: azure-pipelines-agent
template:
metadata:
labels:
app: azure-pipelines-agent
spec:
containers:
- name: agent
image: mcr.microsoft.com/azure-pipelines/vsts-agent:latest
env:
- name: AZP_URL
value: "https://dev.azure.com/{YourOrganizationName} "
- name: AZP_TOKEN
valueFrom:
secretKeyRef:
name: azure-pipelines-token
key: token
- name: AZP_POOL
value: "Pool1"
- name: AZP_AGENT_NAME
value: "agent-pod"
kubectl create secret generic azure-pipelines-token --from-literal=token=
Note:
Replace with a PAT that has “Agent Pools (Read & manage)” scope.
Replace {YourOrganizationName} with your actual Azure DevOps organization.
bash
Copy
kubectl apply -f azure-pipelines-agent.yaml
Step 4: Validate the Agent Connection
Go back to Organization Settings > Agent pools > Pool1 in Azure DevOps.
You should see the agent pod connected and listed as online.
Step 5: Use the Pool in Pipelines
By default, all pipelines in Project1 will now have access to the Pool1 agent pool because you granted access during the pool creation.
In your pipeline YAML files, specify the pool name to use the self-hosted agent:
yaml
Copy
pool:
name: Pool1