Npm@1 - npm v1 任务

使用此任务安装和发布 npm 包或运行 npm 命令。 支持 npmjs.com 和经过身份验证的注册表,例如 Azure Artifacts。

注释

npm 身份验证任务 是使用 Azure Artifacts 进行身份验证的建议方法。 此任务不再采用新功能,仅解决关键 bug。

语法

# 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: 'install' # '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. Optional. Use when command = install || command = ci || command = publish. Verbose logging. 
    #publishPackageMetadata: true # boolean. Optional. Use when command = publish && publishRegistry = useFeed. Publish pipeline metadata. Default: true.
  # Custom registries and authentication
    #customRegistry: 'useNpmrc' # 'useNpmrc' | 'useFeed'. Optional. Use when command = install || command = ci || command = custom. Registries to use. Default: useNpmrc.
    #customFeed: # string. Required when (command = install || command = ci || command = custom) && customRegistry = useFeed. Use packages from this Azure Artifacts/TFS registry. 
    #customEndpoint: # string. Optional. Use when (command = install || command = ci || command = custom) && customRegistry = useNpmrc. Credentials for registries outside this organization/collection. 
  # Destination registry and authentication
    #publishRegistry: 'useExternalRegistry' # 'useExternalRegistry' | 'useFeed'. Optional. Use when command = publish. Registry location. Default: useExternalRegistry.
    #publishFeed: # string. Required when publishRegistry = useFeed && command = publish. Target registry. 
    #publishEndpoint: # string. Required when publishRegistry = useExternalRegistry && command = publish. External Registry.

输入

command - 命令
string。 必填。 允许的值:ciinstallpublishcustom。 默认值:install

指定传递给执行 npm 的命令和参数。

如果参数包含双引号("),请使用斜杠(\)对其进行转义,并使用双引号(")将转义字符串括起来。

默认情况下,包在本地安装。 若要全局安装包,请将 install -g 指定为命令。 有关详细信息,请参阅 全局下载和安装包,下载和安装本地包。


包含 package.json的工作文件夹 workingDir -
string

指定包含目标 package.json.npmrc 文件的文件夹的路径。 选择文件夹,而不是文件。 示例:/packages/mypackage


verbose - 详细日志记录
boolean。 可选。 当 command = install || command = ci || command = publish时使用。

在任务运行时,将详细信息打印到控制台。


customCommand - 命令和参数
stringcommand = custom时是必需的。

运行自定义命令。 示例:dist-tag ls mypackage


customRegistry - 注册表使用
string。 可选。 当 command = install || command = ci || command = custom时使用。 允许的值:useNpmrc(我的 .npmrc 中的注册表),useFeed(我在此处选择的注册表)。 默认值:useNpmrc

指定要使用的注册表。 将 .npmrc 文件提交到源代码存储库,并将其路径设置为值,或将 Azure Artifacts 中的注册表指定为值。


customFeed - 使用此 Azure Artifacts/TFS 注册表中的包
string(command = install || command = ci || command = custom) && customRegistry = useFeed时是必需的。

在生成的 .npmrc中包含所选源。 对于项目范围的源,请使用 ProjectName/FeedNameProjectID/FeedID。 对于组织范围的源,该值应为源名称。


customEndpoint - 此组织/集合外部注册表的凭据
string。 可选。 当 (command = install || command = ci || command = custom) && customRegistry = useNpmrc时使用。

用于项目 .npmrc中的外部注册表的凭据。 将此帐户/集合中的注册表留空;该任务自动使用生成的凭据。


publishRegistry - 注册表位置
string。 可选。 当 command = publish时使用。 允许的值:useExternalRegistry(外部 npm 注册表(包括其他帐户/集合),useFeed(我在此处选择的注册表)。 默认值:useExternalRegistry

指定命令将面向的注册表。


publishFeed - 目标注册表
stringpublishRegistry = useFeed && command = publish时是必需的。

指定帐户中托管的注册表。 必须安装包管理并获得许可才能在此处选择注册表。


publishPackageMetadata - 发布管道元数据
boolean。 可选。 当 command = publish && publishRegistry = useFeed时使用。 默认值:true

将生成/发布管道的元数据(运行 #和源代码信息)与包相关联。


publishEndpoint - 外部注册表
stringpublishRegistry = useExternalRegistry && command = publish时是必需的。

指定要用于发布到外部注册表的凭据。


任务控制选项

除任务输入之外,所有任务都具有控制选项。 有关详细信息,请参阅 控件选项和常见任务属性

输出变量

没有。

注解

注释

项目集合生成服务 和项目的 生成服务 标识必须设置为 参与者,才能使用 Azure Pipelines 将包发布到源。 有关详细信息,请参阅 添加新用户/组

在哪里可以学习 npm 命令和参数?

例子

要求

要求 说明
管道类型 YAML,经典版本,经典版本
运行时间 代理,DeploymentGroup
需求 自承载代理必须具有 功能, 与以下 要求 运行使用此任务的作业: npm
功能 此任务不满足作业中后续任务的任何要求。
命令限制 任何
Settable 变量 任何
代理版本 2.115.0 或更高版本
任务类别 封装件