Next.js CI/CD on Azure DevOps with a self-hosted agent
A practical pipeline for deploying Next.js to private servers with Azure DevOps: self-hosted agents, standalone builds, release directories, health checks and rollback.
By INTELLIA Engineering Team
Published
Last updated
2 min read
Short answer
To deploy Next.js through Azure DevOps to servers on a private network, install a self-hosted agent inside that network, build the app with output set to standalone, publish the build as a pipeline artifact, then have a deployment stage extract it into a new release directory, start it, health-check it and switch traffic, keeping the previous release for instant rollback.
How to set up Next.js CI/CD on Azure DevOps: step by step
- 1
Install a self-hosted agent
Register an Azure Pipelines agent on a machine inside the private network and add it to an agent pool.
- 2
Configure standalone output
Set output to standalone in next.config so the build includes a minimal Node.js server.
- 3
Build and test in CI
Install dependencies, lint, type-check, test and build, then publish the standalone folder as an artifact.
- 4
Deploy to a new release directory
Extract the artifact into a timestamped folder on the target server and install environment configuration.
- 5
Start, health-check and switch
Start the new release on a spare port, check a health route, then switch the reverse proxy or symlink.
- 6
Keep rollback ready
Retain the previous releases so rollback is a single switch.
The problem this solves
Many organizations in Pakistan and the GCC host applications on servers inside their own data center or a private cloud. Those servers are deliberately unreachable from the internet, which rules out cloud-hosted build agents pushing deployments to them. The usual fallback is manual deployment by copying files, which is slow, inconsistent and causes downtime.
Architecture
| Component | Role |
|---|---|
| Azure Repos or GitHub | Source code and pull requests |
| Azure Pipelines (cloud) | Orchestrates stages and stores artifacts |
| Self-hosted agent (private network) | Runs deployment jobs on or near target servers |
| Target servers | Run Node.js processes under a process manager |
| Reverse proxy (Nginx) | Routes traffic to the active release |
The agent only makes outbound HTTPS connections to Azure DevOps. No inbound firewall rules are needed.
Step 1: Standalone build
In next.config.ts, set output: "standalone". The build produces .next/standalone with a server.js and only the required dependencies. Copy public and .next/static alongside it, because they are not included automatically.
Step 2: The CI stage
A typical CI stage:
- Use a pinned Node.js version.
- Install dependencies with
npm ciand a cache. - Run lint, type-check and unit tests.
- Run
next build. - Assemble the standalone folder with
publicand.next/static. - Publish it as a pipeline artifact named with the build number.
Pull requests run the same steps without publishing, so broken code never reaches the main branch.
Step 3: The deployment stage
Run the deployment job in the self-hosted agent pool and target an Azure DevOps environment so approvals and history are recorded. The job:
- Downloads the artifact.
- Extracts it into
/srv/app/releases/<build-number>. - Writes environment configuration from a secure variable group.
- Starts the new release on a spare port with the process manager.
- Calls a health route, for example one that renders a real page, until it returns success or times out.
- Switches the reverse proxy upstream or the
currentsymlink and reloads gracefully. - Stops the old process after connections drain.
- Deletes releases older than the last few.
Rollback
Because previous releases remain on disk, rollback is a switch back to the prior directory and a reload, measured in seconds. Expose it as a separate manual pipeline so on-call engineers do not need server access.
Secrets and configuration
- Store secrets in Azure DevOps variable groups linked to Azure Key Vault where possible.
- Mark secret variables so they are masked in logs.
- Give the agent's service account only the permissions it needs on target servers.
Common pitfalls
- Forgetting static assets: without
.next/static, pages render but styles and scripts return 404. - Health checks that only test the process: a running process can still fail to render pages; check a real route.
- Shared caches between releases: keep each release self-contained.
- Agent as a single point of failure: register at least two agents in the pool for production.
Results to measure
Track deployment duration, downtime per release, change failure rate and time to restore. These are standard DevOps delivery metrics and make the value of the pipeline visible.
We applied this pattern in the zero-downtime Next.js deployment case study. Our cloud and DevOps service sets up the same approach for client applications.
Frequently asked questions
Why use a self-hosted agent instead of Microsoft-hosted agents?
What does output standalone do in Next.js?
How do you achieve zero downtime?
Can the same pipeline deploy to staging and production?
About the author
INTELLIA Engineering Team
Software engineering, Karachi
The engineers who build and support INTELLIA's products and client systems, from WhatsApp integrations and contact-center telephony to ERP rollouts and CI/CD pipelines.
Keep reading
All insightsArticle
Custom software vs off-the-shelf: how to decide
When to build custom software, when to buy SaaS, and when to customize an existing product: a decision framework with cost, risk and time-to-value trade-offs.
· 2 min read
Guide
How to scope a software project and estimate its cost
A practical method to scope a software project and get a reliable cost estimate: outcomes, users, journeys, integrations, non-functional needs, ranges and assumptions.
· 3 min read
Guide
Building an AI support agent with RAG: architecture, evaluation and pitfalls
How to build a retrieval-augmented (RAG) AI support agent that answers from your knowledge base: architecture, chunking, evaluation, guardrails, handover and cost.
· 3 min read
Have a project in mind?
Tell us what you are trying to achieve. A solution architect will reply within one business day with next steps — not a sales script.

