Skip to content

Azure DevOps Pipelines for .NET 10 on a Single Server: Blue-Green Containers and an Agent on the Box

Our real Azure DevOps YAML for .NET 10 on one Linux server: an agent on the box, Docker images, blue-green swaps with rollback and gated migrations.

• Updated • Vukasin Vulovic • 12 min read
Azure DevOps Pipelines for .NET 10 on a Single Server: Blue-Green Containers and an Agent on the Box

I first wrote this post in 2023 as a list of generic Azure DevOps “best practices”. It said nothing you couldn’t find in the docs, so in November 2026 I took it down and rewrote it around what we actually run. This is the setup behind our .NET 10 SaaS template and our own marketing site: one Linux server per environment, a self-hosted Azure DevOps agent living on that server, Docker images in a private registry, and a blue-green swap with automatic rollback for every app. No Kubernetes, no App Service, and no SSH hop in the deploy.

Most Azure DevOps tutorials for .NET end at “deploy to Azure App Service” or “copy files over SSH”. If you run on a single VPS or dedicated server, which is where a lot of small SaaS companies end up once they look hard at the hyperscaler bill, the interesting problems are different: how the agent and production share a box safely, how to deploy without downtime when there’s no load balancer, and how migrations fit in. The YAML below is quoted from our pipelines, with hosts, registry names and IDs replaced by placeholders.

The architecture the pipelines deploy

Per environment (QA and Production), there is:

  • One server running nginx as the only ingress, a Docker network for the shared infrastructure (Postgres behind PgBouncer, Redis, RabbitMQ, object storage, the logging stack), and one container per application.
  • A self-hosted Azure DevOps agent installed on that same server, in an agent pool named per environment.
  • A private Docker registry that every image is pushed to.
  • The static marketing site served by the same nginx straight from disk.

The shared infrastructure is a docker compose stack deployed by its own pipeline. It changes rarely, and the app pipelines assume it is already healthy. The apps (API, the Blazor frontend, admin, status page, docs) are deployed by a single template that every app pipeline reuses.

Why YAML only

Every pipeline here is YAML in the repository. That isn’t only taste. Creating classic build and release pipelines has been disabled by default for new organizations since Sprint 226, and the features we rely on (environments with deployment history, checks on those environments, templates with typed parameters) belong to the YAML world. Existing classic pipelines still run, but nothing new should start there.

Reuse comes from templates. One template owns the whole lifecycle of one app, and its header spells out the stage-name contract other pipelines depend on:

# Encapsulates the full Build -> (optional Migrate) -> blue-green Deploy -> registry
# Cleanup flow for one application, so the per-app pipelines and the release
# orchestrator share a single implementation.
#
# STAGE-NAME CONTRACT — this template emits stages named:
#     Build_<appName>     always
#     Migrate_<appName>   when runMigrations: true
#     Deploy_<appName>    always

A release orchestrator includes that template once per app and runs them in dependency order: Test → Migrate → API → the frontends. Nothing deploys if the unit tests fail.

Installing .NET 10 reliably

The SDK version is set in two places. global.json in the repository decides which SDK the build may use:

{
  "sdk": {
    "version": "10.0.0",
    "rollForward": "latestMajor",
    "allowPrerelease": false
  }
}

Read that rollForward value carefully: latestMajor lets any newer SDK on the agent build the project, including a new major version. .NET 11 shipped on 10 November 2026, so an agent that has the .NET 11 SDK installed will build with it. If you want builds held to .NET 10, use latestFeature, which only rolls forward within the 10.0 band. The pipeline then makes sure a .NET 10 SDK exists on the agent before building:

# No-op when the agent already has the SDK; cheap insurance when it does not.
- task: UseDotNet@2
  displayName: 'Use .NET SDK 10.x'
  inputs:
    packageType: 'sdk'
    version: '10.x'

On a self-hosted agent this matters more than on Microsoft-hosted images. A hosted image ships with several SDK bands preinstalled; your own server has whatever someone installed last. UseDotNet@2 downloads into the agent’s tool cache, so the build never depends on, or changes, the system-wide .NET installation on a production box.

The same applies to Node, which the static site needs. Our website pipeline used NodeTool@0 until a run in November 2026 flagged it as deprecated, and it now uses the replacement:

- task: UseNode@1
  displayName: 'Install Node.js $(nodeVersion)'
  inputs:
    version: '$(nodeVersion)'

Related and easy to miss: Node.js 6, 10 and 16 are removed from the Azure Pipelines agent on 24 November 2026. That’s about the Node runtimes tasks run on, not the Node your build uses. Any old or third-party task still declaring one of those runners may fail afterwards, and an organization setting, “Restrict out of support Node.js versions in pipeline tasks”, lets you find them before the date. On self-hosted agents, keep the agent itself current too: the 4.x agent runs on .NET 8, and agents on operating systems .NET 8 doesn’t support are not upgraded to it.

Building and pushing images

Each app is a Docker image, built and pushed with the built-in Docker@2 task through a Docker Registry service connection (registry type “Others” for a non-Azure registry):

- task: Docker@2
  displayName: Build Docker image
  inputs:
    containerRegistry: '${{ parameters.dockerRegistryServiceConnection }}'
    repository: '${{ parameters.dockerRepoName }}'
    command: build
    Dockerfile: '${{ parameters.dockerfile }}'
    tags: ${{ parameters.dockerImageTag }}
    arguments: '--build-arg BUILD_DATE=$(buildDate) --build-arg VCS_REF=${{ parameters.vcsRef }} --build-arg VERSION=${{ parameters.version }}'
- task: Docker@2
  displayName: Push Docker image
  inputs:
    containerRegistry: '${{ parameters.dockerRegistryServiceConnection }}'
    repository: '${{ parameters.dockerRepoName }}'
    command: push
    tags: ${{ parameters.dockerImageTag }}

Two details worth copying:

  • Build and push are separate commands. Docker@2 ignores arguments when you use the combined buildAndPush command, so build arguments such as the commit SHA only work with a separate build step.
  • Tags are immutable. The default tag is the Azure DevOps build ID. Release builds additionally push the semantic version (1.4.0), so an operator can redeploy a known version without remembering which build produced it. A weekly pipeline prunes old build-ID tags from the registry and keeps the newest three per repository; it never touches the semantic version tags, so every released version stays pullable.

Images are rebuilt per environment from the same tag rather than promoted from QA to Production. Same tag, same Dockerfile and same commit give a reproducible image, and it keeps the registry the only thing the two environments share.

Database migrations as a one-shot container

Migrations run before any app is swapped, as their own stage, and they are deliberately boring:

# Builds Database.Migrator from the CURRENT checkout and runs it once against the
# target environment's Docker network. Building from the same commit as the caller
# guarantees the applied migrations match the code being deployed.
# The migrator is idempotent (skips already-applied migrations). A non-zero exit
# fails the task and blocks any dependent deploy stage.

docker build -f Database.Migrator/Dockerfile -t "${IMAGE}" .
docker run --rm --network "${NETWORK}" -e DOTNET_ENVIRONMENT="${ENVIRONMENT}" "${IMAGE}"

The container joins the environment’s Docker network, so it reaches the database the same way the apps do, with no ports opened for it. If it exits non-zero, set -e fails the step, the Migrate stage fails, and the Deploy stage that depends on it never starts. The old version of every app keeps running against a schema that didn’t change.

The rule that makes this safe is in the orchestrator’s header: migrations are forward-only, and rolling back means redeploying an older tag. That only works if each migration is backward-compatible with the previous app version for at least one release, so add columns before you use them and drop them a release after you stop.

The blue-green deploy, step by step

There’s no load balancer in front of a single server, so the “blue-green” here happens on one host with two ports. The deploy job is a deployment job targeting an environment, which gives you deployment history per environment and a place to attach checks:

- deployment: Deploy
  pool:
    name: ${{ parameters.poolName }}
  environment: ${{ parameters.environment }}
  strategy:
    runOnce:
      deploy:
        steps:
          - template: blue-green-deploy.yml

The template does four things.

1. Record what is running now. Before touching anything it reads the image of the current container, so it knows what to roll back to:

PREV_IMAGE=$(docker inspect --format='{{.Config.Image}}' "${DOCKER_NAME}" 2>/dev/null || echo "")

2. Start a canary on a side port. The new image starts as a second container on the production port plus 10,000, bound to loopback only:

TEMP_PORT=$((HOST_PORT + 10000))
docker run -dit -p 127.0.0.1:${TEMP_PORT}:8080 \
  --name "${CANARY_NAME}" \
  ${NETWORK_ARG} \
  --memory "${{ parameters.memoryLimit }}" \
  --cpus "${{ parameters.cpusLimit }}" \
  -e ASPNETCORE_ENVIRONMENT="${ENVIRONMENT}" \
  "${NEW_IMAGE}"

It then polls the health endpoint, by default 45 attempts two seconds apart. For the API that endpoint is /health/ready, which fails if Postgres, Redis, RabbitMQ or object storage are unreachable, so a canary that can’t reach its dependencies never gets traffic. If the canary doesn’t become healthy, the script prints its last 100 log lines, removes it and fails the job, and the old container never stopped.

3. Swap. Once the canary is healthy, the script removes it, stops the old container and starts the new image on the real port. Be honest with yourself about what this is: the canary proves the image boots and can reach its dependencies, but between stopping the old container and the new one answering, the port has nothing listening for a few seconds. For our traffic that’s acceptable. If it isn’t for yours, put two named upstreams in nginx and switch between them instead of reusing one port.

4. Verify, and roll back if needed. The same health check runs against the production port. If it fails, the script restarts the previous image it recorded in step 1, checks that one too, and fails the pipeline either way, so a rollback is never silent:

if [ -n "${PREV_IMAGE}" ]; then
  echo "--- ROLLBACK: Reverting to previous image ---"
  docker run -dit -p 127.0.0.1:${HOST_PORT}:8080 --name "${DOCKER_NAME}" ... "${PREV_IMAGE}"
fi
exit 1

Two more decisions in that template are worth stealing. Containers publish ports on 127.0.0.1 only, because Docker installs its own iptables rules ahead of the host firewall and nginx is meant to be the only way in. And there is deliberately no “is the old app up?” check before deploying: per the template’s own comment, that check deadlocks the very first deploy, when nothing is running yet. The canary is the real gate.

The static site: a local rsync into the nginx root

Our marketing site is static, and its pipeline is the simplest possible version of “the agent is on the box”: the build runs on the server, and the deploy is a local copy, with no SSH and no keys.

# --delete-after: new files land before stale ones are removed,
# so a crawl mid-deploy never sees a half-empty web root.
rsync -ai --delete-after --checksum "${SOURCE}" "${DEST}"

Three guards in that pipeline each exist because of something the comments record:

  • The build runs at low priority. The agent shares the box with nginx, so nice -n 19 npm run build keeps the live site responsive while the build uses the CPU; the comment notes Search Console logged 5xx errors on a deploy day before this.
  • The artifact folder is wiped before each download. A self-hosted agent keeps its workspace between runs and DownloadPipelineArtifact@2 doesn’t clean its target, so files from older artifacts survived and were copied to the web root on every deploy. A sanity check now compares the pages on disk with the pages in the artifact and warns if anything extra remains.
  • Verification hits the origin, not the CDN. The site sits behind Cloudflare, whose bot protection may challenge a curl from a datacenter IP, so the check pins the request to the local machine and keeps the right hostname:
curl -sk -o /dev/null -w '%{http_code}' --resolve "${HOST}:443:127.0.0.1" "https://${HOST}/"

After the site is live, a final step pings IndexNow with only the URLs that changed, so search engines that support it re-crawl new content quickly.

The agent lives on the production box: doing it safely

Putting the agent on the production server removes a whole class of problems: no SSH keys in service connections, no network copy, and builds that see exactly the environment they deploy to. It also means anything a pipeline runs, runs on production. These are the rules we follow:

  • Run the agent as a dedicated, low-privilege user. It needs write access to the web root and the Docker socket, and nothing else. Microsoft’s agent security guidance says the same: on Linux, a dedicated non-root account with no sudo rights.
  • Treat Docker access as root. Docker’s own docs warn that the docker group grants root-level privileges. An agent that can run containers can do anything on that host, so whoever can edit a pipeline that runs in that pool is effectively a server admin. Restrict pipeline permissions accordingly.
  • Never run pull-request or fork builds on the production pool. Our PR validation runs in a separate agent pool, and each deploy pipeline uses its own per-environment pool. Untrusted code never executes next to production data.
  • Keep runtime secrets on the server, not in YAML. The deploy template takes an optional env file path on the host (/opt/<project>/<service>.env) and passes it to docker run --env-file only when the file exists. The app secrets stay on the box, readable by the deploy user, and never appear in the repository or the pipeline logs.
  • Make deploys deliberate. None of our deploy pipelines trigger on push; they’re queued manually or by a release script. Production has no approval gate in Azure DevOps; instead the release script requires a typed confirmation before it triggers the pipeline. If you’d rather keep that control inside Azure DevOps, attach an approval and an exclusive lock check to the Production environment, so two runs can never deploy to the same server at once.

What a run looks like end to end

For a release to Production, the orchestrator:

  1. builds the solution and runs the unit tests on the production pool’s agent, and stops if anything is red;
  2. builds the migrator from the tagged commit and runs it once against the production database network;
  3. builds, tags and pushes the API image, then blue-green deploys it behind its readiness check;
  4. does the same for the four frontend apps, each depending on the API deploy;
  5. leaves the previous image tags in the registry, so rolling back is “redeploy the previous tag”.

The static site deploys independently, whenever its content changes.

What I’d change next

  • Close the swap gap with two named nginx upstreams per app, so traffic moves only after the new container is healthy on the real port.
  • Move builds off the production server. Building on the box is convenient, but compiling, running tests and building images all compete with live traffic. A separate build agent that only pushes images would leave the production agent doing nothing but deploys.
  • Pin images by digest rather than tag at deploy time, so “the image we tested” and “the image we ran” are provably the same bytes.

If you’re weighing this kind of setup against staying on a hyperscaler, our line-item comparison of AWS, Azure and Hetzner covers the cost side, and the hosting cost review is where we look at your bill and your deploy setup together.