1node.si
← Registry

ado-nodejs-build

cleared

Azure Pipelines Node.js builds using NodeTool@0, npm or yarn scripts, Cache@2 for npm, branch- or parameter-driven env vars (e.g. VITE_* from variable groups), and PublishBuildArtifacts@1 for dist folders. Use when authoring ADO YAML for frontends before Static Web Apps, App Service static content, or embedding into .NET publishes.

files.jsonSKILL.md
---
name: ado-nodejs-build
description: >-
  Azure Pipelines Node.js builds using NodeTool@0, npm or yarn scripts, Cache@2
  for npm, branch- or parameter-driven env vars (e.g. VITE_* from variable
  groups), and PublishBuildArtifacts@1 for dist folders. Use when authoring
  ADO YAML for frontends before Static Web Apps, App Service static content,
  or embedding into .NET publishes.
---

# Azure Pipelines: Node.js / frontend build

## Prerequisites

- `package.json` with a build script; prefer a lockfile (`package-lock.json` or yarn lock) for `npm ci` / `yarn install --frozen-lockfile`.
- Variable group when build-time URLs or keys differ by branch (e.g. `VITE_*`).
- For Azure Static Web Apps: `staticwebapp.config.json` at the app root (copied into `dist` after build)—see **`ado-azure-static-web-apps`**.

## Core steps

1. **`NodeTool@0`** — `versionSpec` (e.g. `18.x`, `20.x`) or pin exact semver when required.
2. **`Cache@2`** (optional) — cache `$(Pipeline.Workspace)/.npm` or `node_modules` keyed on the lockfile.
3. **`npm ci`** or **`npm install`** — prefer `npm ci` when a lockfile is committed.
4. **`npm run build`** (or yarn) — set `workingDirectory` for monorepo packages.
5. **`PublishBuildArtifacts@1`** — publish `dist` (or `$(artifactPath)`) as `ArtifactName` for deploy stages.

Set `name:` / `displayName:` on tasks per **`ci-cd-pipeline-foundation`**.

## Build-time configuration

Map Vite / React API URLs from variable groups with template expressions on `variables:` (branch vs tag), for example `${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}:` — same pattern as **`ci-cd-pipeline-foundation`** ([reference.md](../ci-cd-pipeline-foundation/reference.md)).

Use `Bash@3` or `script:` to `echo` non-secret vars when debugging; never print secrets.

## Pool

Prefer `ubuntu-latest` for Node-only builds. Match the .NET job pool when frontend and backend share one job.

## Downstream

- **`ado-azure-static-web-apps`** consumes the published folder.
- **`ado-dotnet-build-publish`** may run after the frontend build in the same job or stage.

## YAML

See [reference.md](reference.md).