共用方式為


Npm@1 - npm v1 工作

使用此工作來安裝及發佈 npm 套件,或執行 npm 命令。 支援 npmjs.com 和已驗證的登錄,例如 Azure Artifacts。

備註

npm 驗證工作 是向 Azure Artifacts 進行驗證的建議方式。 此工作不再採用新功能,而且只會解決重大錯誤。

語法

# 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。 必須的。 允許的值:ci、、、installpublishcustom 預設值: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、傳統組建、傳統版本
執行於 Agent、DeploymentGroup
需求 自我裝載代理程式必須具備 功能, 符合下列 需求, 執行使用此工作的工作: npm
功能 此工作不符合作業中後續工作的任何需求。
命令限制 任意
Settable 變數 任意
代理程式版本 2.115.0 或更新
工作類別 套件/包裹