运行 在 VSTS 托管生成代理上的 Powershell 中自定义 npm 命令

Run custom npm command in Powershell on VSTS hosted build agent

我需要迭代 运行 一个 npm 命令,并希望在 VSTS 构建步骤中从 PowerShell 任务执行它。我不能在 PowerShell 中使用 "npm <command>",并且还尝试在 VSTS 托管构建代理上的 PowerShell 中使用 "C:\Program Files\nodejs\npm.cmd" "<command>"Invoke-Expression "C:\Program Files\nodejs\npm.cmd" "<command>" 命令 运行。如何从 PowerShell 构建步骤 运行 npm 命令?

此外,<command> 是来自我的 package.json 文件的自定义脚本。它不需要定制。我只是把它放在那里调用自定义 npm VSTS 构建步骤。

您可以使用托管代理通过 PowerShell 任务直接调用 npm 命令。

确保PowerShell任务的工作文件夹(package.json文件夹路径)是正确的。

关于package.json中的自定义脚本,您需要像npm run [script key]那样调用它。

您可以使用 Start-Process 调用 npm 命令并通过以逗号分隔的 -ArgumentList 开关提供参数

示例 Start-Process npm -ArgumentList "运行","build" -wait -wait 开关将等待任务完成