Usar el registro en CI
CI usa el mismo .npmrc (o .yarnrc.yml) que una estación de trabajo de desarrollo — la única diferencia es que el token proviene de un almacén de secretos en lugar de un archivo en disco.
Paso 1: almacenar el token como secreto
Sección titulada «Paso 1: almacenar el token como secreto»- Genera un token específico de CI en Packages → Manage tokens llamado
ci-github(o similar). Usa un token distinto por pipeline para poder revocarlos de forma independiente. - Añádelo como secreto:
- GitHub Actions → Settings del repo → Secrets and variables → Actions →
PIER_NPM_TOKEN. - GitLab CI → Settings del proyecto → CI/CD → Variables →
PIER_NPM_TOKEN(protected, masked).
- GitHub Actions → Settings del repo → Secrets and variables → Actions →
Paso 2: escribir el .npmrc en el job
Sección titulada «Paso 2: escribir el .npmrc en el job»GitHub Actions — npm / pnpm / bun
Sección titulada «GitHub Actions — npm / pnpm / bun»name: buildon: [push]jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 24 - name: Configure Pier registry run: | cat > .npmrc <<EOF registry=https://YOUR-PIER-HOST/registry/npm/ //YOUR-PIER-HOST/registry/npm/:_authToken=${PIER_NPM_TOKEN} always-auth=true EOF env: PIER_NPM_TOKEN: ${{ secrets.PIER_NPM_TOKEN }} - run: npm ci - run: npm run buildPara pnpm reemplaza npm ci por pnpm install --frozen-lockfile, y para bun por bun install --frozen-lockfile.
GitHub Actions — yarn 4 (berry)
Sección titulada «GitHub Actions — yarn 4 (berry)» - name: Configure Pier registry (yarn berry) run: | cat > .yarnrc.yml <<EOF npmRegistryServer: "https://YOUR-PIER-HOST/registry/npm/" npmAuthToken: "${PIER_NPM_TOKEN}" npmAlwaysAuth: true nodeLinker: node-modules EOF env: PIER_NPM_TOKEN: ${{ secrets.PIER_NPM_TOKEN }} - run: corepack enable && yarn install --immutableGitLab CI
Sección titulada «GitLab CI»build: image: node:24 before_script: - | cat > .npmrc <<EOF registry=https://YOUR-PIER-HOST/registry/npm/ //YOUR-PIER-HOST/registry/npm/:_authToken=${PIER_NPM_TOKEN} always-auth=true EOF script: - npm ci - npm run buildPaso 3: publicar desde CI (opcional)
Sección titulada «Paso 3: publicar desde CI (opcional)» - name: Publish if: startsWith(github.ref, 'refs/tags/v') run: npm publish env: NPM_CONFIG_REGISTRY: https://YOUR-PIER-HOST/registry/npm/El .npmrc escrito en el paso 2 lleva el bearer; npm publish lo recoge automáticamente.
Consejos
Sección titulada «Consejos»- Un token por pipeline. Revócalo sin tocar nada más.
always-auth=truees obligatorio para yarn 1; inofensivo para npm/pnpm/bun. Yarn 4 requierenpmAlwaysAuth: trueen.yarnrc.yml.- Cachea
node_modulesentre ejecuciones. El proxy es rápido, pero saltarse la instalación por completo es más rápido aún — usa la caché estándar de actions/setup-node. - Verifica que el registro es accesible antes de instalar — un simple
curl -sf https://your-pier-host/registry/npm/-/pingde una línea ahorra un confuso error de instalación de 5 minutos si Traefik o el DNS se están portando mal.
Relacionado
Sección titulada «Relacionado»- Configuración — la forma del .npmrc, en detalle.
- Guías por cliente — particularidades específicas de cada cliente.
- Solución de problemas — qué significa cada 401/403/409.