npm task

Azure Pipelines | TFS 2018 | TFS 2017 | TFS 2015

Use this task in a build or release pipeline to install and publish npm packages.

Note

In Microsoft Team Foundation Server (TFS) 2018 and previous versions, build and release pipelines are called definitions, service connections are called service endpoints, stages are called environments, and jobs are called phases.

Install npm packages

Demands

npm

YAML snippet

# npm
# Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Package Management.
- task: Npm@1
  inputs:
    #command: 'install' # Options: install, publish, custom
    #workingDir: # Optional
    #verbose: # Optional
    #customCommand: # Required when command == Custom
    #customRegistry: 'useNpmrc' # Optional. Options: useNpmrc, useFeed
    #customFeed: # Required when customRegistry == UseFeed
    #customEndpoint: # Optional
    #publishRegistry: 'useExternalRegistry' # Optional. Options: useExternalRegistry, useFeed
    #publishFeed: # Required when publishRegistry == UseFeed
    #publishEndpoint: # Required when publishRegistry == UseExternalRegistry

Arguments

Argument Description
Command npm command to run. Select install here.
Working folder with package.json Path to the folder containing the target package.json and .npmrc files. Select the folder, not the file e.g. "/packages/mypackage".
Custom registries and authentication
Registries to use Leave this section blank to use packages from npmjs directly. Otherwise, select one of these options:
Registries in my .npmrc:
  • Select this option to use feeds specified in a .npmrc file you've checked into source control.
    • Credentials for registries outside this organization/collection can be used to inject credentials you've provided as an npm service connection into your .npmrc as the build runs.
Use packages from this Azure Artifacts/TFS registry:
  • Select this option to use one Package Management feed in the same organization/collection as the build.
Advanced
Verbose logging Enables verbose logging.
Control options

Publish npm packages

Demands

npm

Arguments

Argument Description
Command npm command to run. Select publish here.
Working folder with package.json Path to the folder containing the target package.json and .npmrc files. Select the folder, not the file e.g. "/packages/mypackage".
Destination registry and authentication
Registry location
  • Registry I select here publishes to a Package Management registry in the same organization/collection as the build. After you select this option, select the target registry from the dropdown.
  • External npm registry (including other organizations/collections) publishes to an external server such as npm, MyGet, or a Package Management feed in another Azure DevOps organization or TFS collection. After you select this option, create and select an npm service connection.
Advanced
Verbose logging Enables verbose logging.
Control options

Custom npm command

Demands

npm

Arguments

Argument Description
Command npm command to run. Select custom here.
Working folder with package.json Path to the folder containing the target package.json and .npmrc files. Select the folder, not the file e.g. "/packages/mypackage".
Command and arguments The custom command and arguments you wish to be executed.
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\"}".
Custom registries and authentication
Registries to use Leave this section blank to use packages from npmjs directly. Otherwise, select one of these options:
Registries in my .npmrc:
  • Select this option to use feeds specified in a .npmrc file you've checked into source control.
  • Credentials for registries outside this organization/collection can be used to inject credentials you've provided as an npm service connection into your .npmrc as the build runs.
Use packages from this Azure Artifacts/TFS registry:
  • Select this option to use one Package Management feed in the same organization/collection as the build.
Control options

Examples

Build: gulp

Build your Node.js app with gulp

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

Q & A

Where can I learn npm commands and arguments?

npm docs

Do I need an agent?

You need at least one agent to run your build or release. Get an agent for Linux, macOS, or Windows.

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.

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.