Back to Blog
1 min read

Self-Hosted Agents in Azure DevOps

Self-hosted agents in Azure DevOps provide control over your build environment, enabling custom configurations and access to on-premises resources.

Setting Up Self-Hosted Agents

# Dockerfile for containerized agent
FROM ubuntu:22.04

RUN apt-get update && apt-get install -y \
    curl \
    git \
    jq \
    libicu70 \
    docker.io \
    && rm -rf /var/lib/apt/lists/*

# Install .NET SDK
RUN curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 7.0

# Download agent
WORKDIR /azp
RUN curl -LsS https://vstsagentpackage.azureedge.net/agent/3.220.0/vsts-agent-linux-x64-3.220.0.tar.gz | tar -xz

COPY start.sh .
RUN chmod +x start.sh

ENTRYPOINT ["./start.sh"]
#!/bin/bash
# start.sh
./config.sh --unattended \
  --url "$AZP_URL" \
  --auth pat \
  --token "$AZP_TOKEN" \
  --pool "$AZP_POOL" \
  --agent "${AZP_AGENT_NAME:-$(hostname)}" \
  --replace

./run.sh

Kubernetes Deployment

# Azure DevOps agent on Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
  name: azp-agent
spec:
  replicas: 3
  selector:
    matchLabels:
      app: azp-agent
  template:
    spec:
      containers:
        - name: agent
          image: myregistry/azp-agent:latest
          env:
            - name: AZP_URL
              value: https://dev.azure.com/myorg
            - name: AZP_TOKEN
              valueFrom:
                secretKeyRef:
                  name: azp-secrets
                  key: token
            - name: AZP_POOL
              value: kubernetes-pool

Self-hosted agents provide flexibility for specialized build requirements and secure access to internal resources.

Michael John Peña

Michael John Peña

Senior Data Engineer based in Sydney. Writing about data, cloud, and technology.