Using NPM Connector in Tekton Task
Using NPM Connector in Tekton Tasks enables centralized management of npm registry access and secretless package operations during task execution.
This document shows how to use multi-connector capability in one TaskRun to:
- pull dependencies from a mirror registry
- publish packages to a target registry
TOC
Requirements for Tekton TaskMulti-Connector ScenarioPrepare ConnectorsTaskRun Example withnodejs:0.1CA Bundle ExampleUsing ResourceInterface in Pipeline IntegrationFurther ReadingRequirements for Tekton Task
Not all Tekton Tasks can use NPM Connector.
NPM Connector injects temporary registry configuration through Connectors CSI Driver. It provides npmrc and yarnrc configurations that generate .npmrc, .yarnrc.yml, and ca.crt.
Therefore, Tekton Tasks must meet the following requirements:
- support mounting an
.npmrcfile via Workspace - support mounting a CA certificate via Workspace (required for HTTPS repositories in forward-proxy MITM mode)
The catalog nodejs task (0.1) already supports these workspaces:
npm-config: package manager configuration workspaceca-bundle: custom CA workspace
Multi-Connector Scenario
To install dependencies from one registry and publish to another registry in the same TaskRun, prepare two NPM connectors:
npm-mirror-connector: setspec.params.registryType=mirrornpm-publish-connector: setspec.params.registryType=publish
When both connectors are mounted through volumeAttributes.connectors, NPM configuration is rendered with this behavior:
- dependency download prefers connector with
registryType=mirror - for
nodejs:0.1, the publish endpoint is controlled bypublishRepository; use theregistryType=publishconnector address as thepublishRepositoryvalue
Before using multiple connectors in one CSI volume, enable enable-multi-connector in connectors-config.
Prepare Connectors
Example connector pair:
TaskRun Example with nodejs:0.1
After both connectors are ready, reference the built-in nodejs task directly.
In this example:
npm ciresolves dependencies using rendered registry settings from the mirror connectorpublishRepositorytriggersnpm publish --registry ...in thenodejstaskcaFileName: ca.crttellsnodejs:0.1to load the certificate generated by NPM connector from theca-bundleworkspace
CA Bundle Example
In forward-proxy MITM mode, all HTTPS npm repository traffic goes through connectors-proxy and must trust the proxy CA.
Therefore, when your dependency or publish repository uses https://, always mount ca-bundle and set caFileName to ca.crt.
In this setup, ca.crt is rendered by NPM connector and consumed by nodejs:0.1 through the ca-bundle workspace, so both dependency download and package publish can access HTTPS repositories successfully.
Using ResourceInterface in Pipeline Integration
If you integrate connectors from Pipeline UI instead of hand-writing CSI fields, use the NPMRepository ResourceInterface.
Typical usage flow:
- In Pipeline Integration, select interface category
NPMRepository. - Select a primary connector with
spec.params.registryType=publish, then add other connectors (for example aregistryType=mirrorconnector) to the same integration item. This keeps connector selection consistent with laterpublishRepositoryparameter selection in the task. - Bind integration workspaces to the task's
npm-configandca-bundleworkspaces.
At runtime, ResourceInterface renders connector workspace bindings for you:
npm-configmounts merged config from selected connectors (multi-connector)ca-bundlemounts certificate configuration for TLS trust
This means users can keep using nodejs:0.1 directly while delegating connector selection and workspace rendering to Pipeline Integration.
For details, see ResourceInterface and Pipeline Integration.