npm task
Azure DevOps Services | Azure DevOps Server 2022 | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018
Use this task to install and publish npm packages.
Note
The npm Authenticate task is the recommended way to authenticate with Azure Artifacts. This task no longer takes new features and only critical bugs are addressed.
Note
In Microsoft Team Foundation Server (TFS) 2018 and previous versions, build and release pipelines are called definitions, runs are called builds, service connections are called service endpoints, stages are called environments, and jobs are called phases.
YAML snippet
# npm v1
# Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
- task: Npm@1
inputs:
command: ci | install | publish | custom # Required. Command. Default: install
workingDir: string # Working folder that contains package.json.
customCommand: string # Required when command = custom. Command and arguments.
# Advanced
verbose: boolean # Verbose logging.
publishPackageMetadata: boolean # Optional. Use when command = publish && publishRegistry = useFeed. Publish pipeline metadata. Default: True
# Custom registries and authentication
customRegistry: useNpmrc | useFeed # Registries to use. Default: useNpmrc
customFeed: string # Required when customRegistry = useFeed. Use packages from this Azure Artifacts/TFS registry.
customEndpoint: string # Optional. Use when customRegistry = useNpmrc. Credentials for registries outside this organization/collection.
# Destination registry and authentication
publishRegistry: useExternalRegistry | useFeed # Registry location. Default: useExternalRegistry
publishFeed: string # Required when publishRegistry = useFeed. Target registry.
publishEndpoint: string # Required when publishRegistry = useExternalRegistry. External Registry.
Install npm packages
Demands
Arguments
| Argument | Description |
|---|---|
commandCommand |
(Required) npm command to run. Default: install. Options: install, publish, custom, ci. |
workingDirWorking folder that contains package.json |
Path to the folder containing the target package.json and .npmrc files. Select the folder, not the file e.g. "/packages/mypackage". |
verbose Verbose logging |
Boolean. Select to print more information to the console on run |
customRegistryRegistry to use |
You can either commit a .npmrc file to your source code repository and set its path or select a registry from Azure Artifacts.useNpmrc .npmrc file is present, the task will default to using packages directly from npmjs. useFeed |
Publish npm packages
Demands
Arguments
| Argument | Description |
|---|---|
commandCommand |
(Required) npm command to run. Select publish here. |
workingDirWorking folder that contains package.json |
Path to the folder containing the target package.json and .npmrc files. Select the folder, not the file e.g. "/packages/mypackage". |
verbose Verbose logging |
Boolean. Select to print more information to the console on run. |
customRegistryRegistry to use |
You can either commit a .npmrc file to your source code repository and set its path or select a registry from Azure Artifacts.useNpmrc .npmrc file is present, the task will default to using packages directly from npmjs. useFeed |
Custom npm command
Demands
Arguments
| Argument | Description |
|---|---|
commandCommand |
(Required) npm command to run. Select custom here. |
workingDirWorking folder that contains package.json |
Path to the folder containing the target package.json and .npmrc files. Select the folder, not the file e.g. "/packages/mypackage". |
customCommandCommand and arguments |
(Required) Custom command to run, e.g. "dist-tag ls mypackage". If your arguments contain double quotes ("), escape them with a slash (\), and surround the escaped string with double quotes ("). Example: to run npm run myTask -- --users='{"foo":"bar"}', provide this input: run myTask -- --users="{"foo":"bar"}". |
customRegistryRegistry to use |
You can either commit a .npmrc file to your source code repository and set its path or select a registry from Azure Artifacts.useNpmrc .npmrc file is present, the task will default to using packages directly from npmjs. useFeed |
Examples
Build your Node.js app with gulp
Open source
This task is open source on GitHub. Feedback and contributions are welcome.
FAQ
Where can I learn npm commands and arguments?
Do I need an agent?
You need at least one agent to run your build or release.
I'm having problems. How can I troubleshoot them?
See Troubleshoot Build and Release.
I can't select a default agent pool and I can't queue my build or release. How do I fix this?
See Agent pools.
My NuGet push task is failing with the following error: "Error: unable to get local issuer certificate". How can I fix this?
This can be fixed by adding a trusted root certificate. You can either add the NODE_EXTRA_CA_CERTS=file environment variable to your build agent, or you can add the NODE.EXTRA.CA.CERTS=file task variable in your pipeline. See Node.js documentation for more details about this variable. See Set variables in a pipeline for instructions on setting a variable in your pipeline.
I use TFS on-premises and I don't see some of these features. Why not?
Some of these features are available only on Azure Pipelines and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.
My Pipeline needs to access a feed in a different project
If the pipeline is running in a different project than the project hosting the feed, you must set up the other project to grant read/write access to the build service. See Package permissions in Azure Pipelines for more details.
Feedback
Submit and view feedback for