npm task

Azure Pipelines | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 - TFS 2015

Use this task to install and publish npm packages.

Note

Moving forward, the npm Authenticate task is the recommended way to use authenticated feeds within a pipeline.

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
# Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
- 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
    #publishPackageMetadata: true # Optional
    #publishEndpoint: # Required when publishRegistry == UseExternalRegistry

Install npm packages

Demands

npm

Arguments

Argument Description
command
Command
(Required) npm command to run. Select install here
workingDir
Working 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".
advanced
Verbose logging
Select to print more information to the console on run
customRegistries
Registries 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
  • Select this option to use feeds specified in a .npmrc file you've checked into source control. If no .npmrc file is present, the task will default to using packages directly from npmjs.
  • 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.
    useFeed
  • Select this option to use one Azure Artifacts feed in the same organization/collection as the build.
  • Publish npm packages

    Demands

    npm

    Arguments

    Argument Description
    command
    Command
    (Required) npm command to run. Select publish here.
    workingDir
    Working 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".
    advanced
    Verbose logging
    Select to print more information to the console on run
    customRegistries
    Registries 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
  • Select this option to use feeds specified in a .npmrc file you've checked into source control. If no .npmrc file is present, the task will default to using packages directly from npmjs.
  • 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.
    useFeed
  • Select this option to use one Azure Artifacts feed in the same organization/collection as the build.
  • Custom npm command

    Demands

    npm

    Arguments

    Argument Description
    command
    Command
    (Required) npm command to run. Select custom here.
    workingDir
    Working 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".
    customCommand
    Command 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"}".
    customRegistries
    Registries 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
  • Select this option to use feeds specified in a .npmrc file you've checked into source control. If no .npmrc file is present, the task will default to using packages directly from npmjs.
  • 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.
    useFeed
  • Select this option to use one Azure Artifacts feed in the same organization/collection as the build.
  • Examples

    Build: gulp

    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?

    npm docs

    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.

    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.