在自托管VSO代理上运行NPM

set*_*dnz 5 azure node.js npm azure-devops azure-pipelines

我在Azure上使用Azure VM和Visual Studio Release插件设置了VSO代理.我还安装了最新版本的node.js(使用NVM for windows).我在安装VSO代理时使用了默认帐户,因为我用于远程桌面的凭据不起作用.

我可以远程进入机器并运行我试图从VSO运行的构建脚本.我也可以使用它运行纯粹的.NET构建.我的问题在于使用npm来安装我的软件包并运行构建.

我已经像这样建立了对构建的需求:

npm | exists

我从控制面板上设置了VSO代理的功能,如下所示:

npm | C:\Program Files\nodejs\npm.cmd

也试过了

npm | C:\Program Files\nodejs

我可以在该文件夹中看到npm.cmd,当我远程使用该路径时,我可以运行npm.我还根据这个问题重新启动了VSO代理服务:

TFS构建代理无法定位npm

重启服务器并完成了"更新所有代理"几次.我的路径中也有npm,并且能够在登录时正常执行.

编辑:

错误信息:

npm : The term 'npm' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\work-folder\1\s\azure-deploy.ps1:24 char:1
+ npm update
+ ~~~
+ CategoryInfo : ObjectNotFound: (npm:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)

我也尝试添加如下所述的行:

$env:Path += ";C:\Program Files\nodejs\"

同样的错误.一个Write-Host我的$ ENV的:路径写入该命令给出后:

C:\Application Intallers\agent (1)\agent\worker\Modules\Microsoft.TeamFoundation.DistributedTask.Task.Internal\NativeBinaries\amd64;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Users\propertyplotdev\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Microsoft SDKs\Azure\CLI\wbin;C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy;C:\Program Files\nodejs;C:\Windows\ServiceProfiles\LocalService\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin;C:\Windows\ServiceProfiles\LocalService\.dnx\bin;C:\Program Files\nodejs\
Run Code Online (Sandbox Code Playgroud)

既存在C:\Program Files\nodejs\npm.cmdC:\Program Files\nodejs\node.js存在,NETWORK SERVICE对它们有权限.(以及Adiministrators,SYSTEM和我的登录)

set*_*dnz 7

解决方案是使用常规安装程序安装node.js:

https://nodejs.org/en/download/

然后这工作.还有其他问题但是这个问题的直接问题是通过不使用nvm来安装节点来解决的.然后,我可以在VSO构建定义界面中添加npm任务.

  • 您将需要重新启动代理服务(它将在services.msc下称为"VSTS代理"),或者如果以交互方式运行代理,只需重新启动它即可. (2认同)