Skip to content
RankCore.AI
← All posts

Azure DevOps Part 3: Agents, Variables, Secrets, and Service Connections

· azure-devops-series, Azure Pipelines, Agents, Key Vault, Service Connections

Azure DevOps series

All six parts of the series, in order:

  1. Part 1: Core Services & Architecture
  2. Part 2: Repos, Branching & YAML Pipelines
  3. Part 3: Agents, Variables, Secrets & Service Connections (you are here)
  4. Part 4: CI/CD, Build, Artifacts & Release
  5. Part 5: Multi-Stage Pipelines, Security & Troubleshooting
  6. Part 6: End-to-End Workflow, Best Practices & Interview Prep

Part 2 left you with a YAML skeleton and a protected main. Part 3 is the plumbing that makes that YAML safe to run: the machine that executes each job, the variables and secrets it may see, and the service connections that let it talk to Azure, GitHub, Docker Hub, or Kubernetes. The short video above walks that path. This article follows the same order and adds the trade-offs to settle before a pipeline is trusted near production.

What actually runs your jobs

A pipeline definition is inert until an agent executes it. The model is the right one: a job is scheduled onto an agent, and agents are grouped into an agent pool. A job occupies one agent from start to finish, and its steps share a workspace and a job-scoped identity. Two jobs can run in parallel only if two agents are available and you have not declared a dependency.

When you write pool: vmImage: ubuntu-latest, you are naming a Microsoft-hosted image in the built-in Azure Pipelines pool. When you write pool: name: MyCompany-Linux, you are asking Azure DevOps to pick an agent from a pool you own, often with demands so the job lands on the right machine. The choice is which kind of agent, who patches it, and what it may reach.

Microsoft-hosted agents: start here unless you cannot

Microsoft-hosted agents are the default I recommend for standard builds and for work that does not need to touch a private network: nothing to install, a fresh machine for every job on Windows, Linux, or macOS, and a good fit for standard and open-source builds.

Microsoft-hosted agents: ready to use, a fresh machine every job on Windows, Linux, or macOS, and a fit for standard builds and open-source projects

Microsoft-hosted agents are the low-friction default: nothing to install, a clean VM per job, and images for Windows, Linux, and macOS.

That "fresh machine every job" property is a security feature as much as a convenience: a compromised step or leftover credential does not survive into the next run. The trade-off is the opposite of self-hosted agents. You cannot preload a large SDK and expect it to still be there, join the VM to your domain, or reach services that live only on a private network unless you have a supported path out.

Image selection matters. ubuntu-latest currently maps to Ubuntu 24.04, macOS-latest currently maps to macOS 26, and windows-latest is a moving alias, so treat the hosted-agent software document as the source of truth. If a toolchain must stay still, pin a specific image such as ubuntu-24.04 and plan the upgrade yourself.

Microsoft-hosted jobs also have time and resource limits that change with project visibility and purchased parallel jobs. Do not design a long integration suite that only fits on a self-hosted box, then be surprised when the hosted job is canceled. Check the current limits before you promise a schedule.

A typical hosted pool declaration looks like this:

pool:
  vmImage: ubuntu-24.04

Move off hosted agents when you have a concrete reason: private-network access, a licensed tool you cannot install every job, a compliance image you must control, or a measured performance need that a warm machine actually wins.

Self-hosted agents: control, private networks, and a maintenance bill

Self-hosted agents run on infrastructure you provide: a VM, a scale set, a container, or a machine in a data center. Teams choose them because they maintain the infrastructure, control the tools, can reach private networks and on-premises systems, and fit enterprise and compliance needs.

Self-hosted agents: your own infrastructure, full control of tools, access to private networks and on-premises systems, and a fit for enterprise and compliance needs

Self-hosted agents trade Microsoft's convenience for your control: private-network reach, custom toolchains, and a patching bill that is now yours.

A self-hosted agent is a production-adjacent server. It needs patching, identity, disk hygiene, and a story for when it is offline. If you run jobs on a shared desktop "agent," you will spend a year chasing "it worked yesterday." Prefer a pool of identically imaged machines, auto-scaled if you can, with the agent service running unattended.

Microsoft also offers managed options between the two models: Managed DevOps Pools and VM-scale-set agents. You still get agents that can live in your virtual network, but Azure handles more of the provisioning. For private-network reach without babysitting VMs, that is often a better first step than a hand-built pool.

Network placement is the usual forcing function. If the pipeline must deploy to an internal Kubernetes cluster, talk to a private feed, or test a system with no public endpoint, a Microsoft-hosted agent cannot see the target. Put the self-hosted pool in a subnet that can reach those systems, and lock the pool so only the pipelines that need it can use it.

Registering an agent is documented in the self-hosted agent guide. The operational rule I care about is this: use a dedicated service account, avoid the catch-all Default pool when you can, and never place a production-privileged connection on a pool that also runs untrusted or fork-triggered jobs.

pool:
  name: corp-linux

Capabilities and demands: send the job to the right machine

A pool can hold mixed machines. Capabilities are the facts an agent advertises — operating system, installed software, user-defined keys. Demands are the facts a job requires. The video shows a compact example: Agent.OS: Linux, Docker: true, DotNet: 8.0, and a comment that demands pick the right agent.

Agent capabilities example: Agent.OS Linux, Docker true, DotNet 8.0, with a note that demands pick the right agent

Capabilities are what the agent has. Demands are what the job requires. Together they keep a Windows-only step off a Linux box.

In YAML, that look-up is expressed on the pool. The demands syntax supports an exists check or an equality check:

pool:
  name: corp-linux
  demands:
  - Agent.OS -equals Linux
  - docker
  - DotNet

Microsoft-hosted images already advertise a large set of built-in capabilities, which is why you rarely write demands against vmImage. Demands matter most on self-hosted pools. I still prefer dedicated pools (Linux CI, Windows CI, prod-deploy) over one giant pool with a thicket of demands. A mislabeled capability is a silent queue backup: the job waits for an agent that never appears.

Keep custom capabilities truthful and automated. If an image update removes Docker, the capability should disappear with it. A hand-edited capability that no longer matches the box is worse than none at all.

Variables, groups, the Library, and secure files

Not every value in a pipeline is a secret, but every value needs a place to live. The four-part map is accurate: variables can be set at pipeline, stage, job, or step scope; variable groups are shared across pipelines; the Library is where those groups live; and secure files hold certificates and keys.

Variables at pipeline, stage, job, and step scope, plus variable groups, the Library, and secure files for certificates and keys

Non-secret configuration belongs in variables and groups. Certificates and keys that are files belong in the Library as secure files, not in the repo.

A variable defined in YAML is fine for a build configuration or a folder path. A variable group is the right home for values several pipelines share, such as a subscription ID or a non-secret endpoint. You reference a group like this:

variables:
- group: webapp-settings
- name: buildConfiguration
  value: Release

Scope and precedence matter. A variable at a lower scope can override a higher one, and queue-time variables add another layer. Avoid the same name in three places. If buildConfiguration is in a group and also in the YAML, someone will lose a day wondering which value ran.

Variable groups have their own permissions in the Library. Do not make every group readable by every pipeline. A group that holds production settings should be allowed only on the pipelines that deploy to production. A signing certificate or kubeconfig should be a secure file downloaded in the job that needs it, not checked into Git.

Secrets: encrypt, mask, and prefer Key Vault

When a variable is marked secret, Azure Pipelines encrypts it (RSA 2048-bit) and masks it in logs as ********. That is necessary, and it is not sufficient. Masking does not stop a script from writing the value to a file or shipping it to an external logger. Treat secret variables as harder to leak by accident, not impossible to leak.

The stronger pattern, and the one I want for production, is to link Azure Key Vault so secrets are fetched at runtime and are not stored in the pipeline. You typically do this by linking a Key Vault to a Library variable group, or by using the AzureKeyVault@2 task. The identity that reads the vault is a service connection — the same design problem as the next section.

Secrets: a secret variable is encrypted and masked in logs, while Azure Key Vault secrets are fetched at runtime and not stored in the pipeline

Secret variables are encrypted and masked. Key Vault goes further: the value is fetched at runtime and is not stored in the pipeline.

The golden rule on screen is the right one: never hardcode a secret in YAML. Not in a script: line, not in a variable value:, not in a template parameter, and not in a comment "just for local testing." If a secret has ever been in Git history, rotate it. The repo will be cloned, forked, and backed up in places you do not expect.

A few related rules the video leaves implicit. Do not pass secrets on a command line that process listings can capture; prefer environment variables the task already treats as secret. Do not use echo to "check" a secret, and be careful with System.Debug and with publishing a whole workspace as an artifact. If a log ever shows a secret, rotate it first, then fix the step.

Service connections: credentials the pipeline may use, but not own

A service connection is a stored, permissioned credential that a pipeline uses to talk to an external system. The video names the four you will meet most often: Azure, GitHub, Docker Hub, and Kubernetes. Credentials are stored securely, and the pipeline uses the connection by name rather than embedding a password.

Service connections for Azure, GitHub, Docker Hub, and Kubernetes, with credentials stored securely

Service connections keep credentials out of YAML. The common four are Azure, GitHub, Docker Hub, and Kubernetes.

In a task, the connection is just a name. That name is also an authorization boundary: a pipeline cannot use a connection unless it is allowed to.

- task: AzureCLI@2
  inputs:
    azureSubscription: azure-prod-arm
    scriptType: bash
    scriptLocation: inlineScript
    inlineScript: az group show --name rg-web-prod

How those connections authenticate is the part teams get wrong. The table is a fair map: Azure uses a service principal, scoped to a subscription, a resource group, or a single resource; GitHub uses a GitHub App or token; Docker Hub uses an access token; Kubernetes uses a kubeconfig or service account.

How service connections authenticate: Azure with a service principal, GitHub with an App or token, Docker Hub with an access token, and Kubernetes with a kubeconfig or service account, scoped to a subscription, resource group, or single resource

Scope the Azure identity to a subscription, a resource group, or a single resource — never "the whole tenant because it was easier."

That Azure row needs an update. A service principal (an Entra ID app registration or a managed identity) is still the identity, but the recommended credential is no longer a long-lived client secret. Microsoft recommends workload identity federation for Azure Resource Manager connections, so Azure DevOps presents a short-lived token instead of a password you have to rotate. Use federation for new connections, and plan to migrate old secret-based ones.

Match the other rows with the same least-privilege instinct. Prefer a GitHub App over a personal access token that belongs to a human who will leave. Prefer a Docker access token with only the scopes you need. For Kubernetes, prefer a dedicated service account with a narrow RoleBinding over a copied admin kubeconfig.

Create separate connections for non-production and production. A CI pipeline that builds a pull request should not be authorized to use azure-prod-arm. Restrict connection use in the project, and put environment approvals in front of any stage that consumes the production connection.

Best practices: least privilege, rotation, and checks before production

Best practices: least privilege, rotate credentials regularly, and approvals and checks before production

Three controls that belong on every production path: least privilege, regular credential rotation, and approvals or checks before production.

Least privilege. Grant the identity the smallest Azure role on the smallest scope. Contributor on a subscription is almost never required for a deploy; often you want a narrower role on one resource group. Grant a pipeline access only to the variable groups, secure files, and connections it needs. Keep production-capable agents and connections away from public projects and from fork pull requests.

Rotate credentials regularly. Federation reduces how often you rotate a secret, because there may be no long-lived secret to rotate. You still rotate GitHub tokens, Docker tokens, kubeconfig material, and any remaining client secrets, and you still review Entra role assignments. If a secret might have appeared in a log or a chat paste, rotate it immediately.

Approvals and checks before production. Environment approvals and checks are the last control the YAML cannot talk its way around. Require a human approval, a business-hours window, a required template, or a work-item check — whatever your release standard is — on the production environment, not only as a friendly stage condition in the file. Parts 4 and 5 pick this up in the release and multi-stage discussion.

A checklist for a new project:

  • Prefer Microsoft-hosted agents until a private network, license, or compliance rule forces a self-hosted or managed pool.
  • Pin agent images when the toolchain cannot float with -latest.
  • Put shared non-secrets in Library groups, and restrict who can use the production groups.
  • Put secrets in Key Vault or in secret variables, never in YAML.
  • Use workload identity federation for new Azure Resource Manager connections.
  • Split dev and production connections, and require environment approvals on production.
  • Do not run untrusted or fork PR jobs on an agent or connection that can reach production.

With agents, variables, secrets, and connections in place, the pipeline is ready to build, publish artifacts, and release through environments. That is Part 4.

Previous: Part 2: Repos, Branching & YAML Pipelines · Next: Part 4: CI/CD, Build, Artifacts & Release

If you want more short, practical lessons like this on AI, code, cloud, and security, follow @rankcore.ai.

Want to go deeper?

Our step-by-step video courses turn these ideas into results.

See courses

Comments

Sign in or create a free account to join the discussion.

No comments yet — be the first.