6

I have set up a VSO agent using an Azure VM and the Visual Studio Release plugin on Azure. I have also installed the latest version of node.js (using NVM for windows). I used the default account when installing the VSO agent as the credentials I used for remote desktop would not work.

I can remote into the machine and run the build script I am trying to run from VSO. I can also run purely .NET builds with it and its fine. My issues comes in using npm to install my packages and run the build.

I have set up a demand on the build like so:

npm | exists

I have set up a capability on the VSO agent from the control panel like so:

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

Have also tried

npm | C:\Program Files\nodejs

I can see npm.cmd in that folder and I can run npm when I remote in using that path. I have also restarted the VSO Agent service as per this question:

TFS build agent cannot locate npm

Restarted the server and also done the "update all agents" a few times. I have also got npm in my path and am able to execute it normally when logged in.

Edit:

Error message:

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

I have also tried adding the line as described below:

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

Same error. A Write-Host of my $env:Path write after that command gives:

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\

Both C:\Program Files\nodejs\npm.cmd and C:\Program Files\nodejs\node.js exist and NETWORK SERVICE has permission on them. (As well as Adiministrators, SYSTEM and my login)

4

3 回答 3

8

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

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

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

于 2016-01-27T00:19:12.667 回答
3

确保 npm 安装在“C:\Program Files\nodejs\”文件夹中,然后在 PowerShell 脚本中添加以下内容:

$env:Path += ";C:\Program Files\nodejs\"
于 2016-01-26T05:18:33.967 回答
1

尝试从以下位置添加run npm 命令构建任务:

添加构建步骤 -> 添加任务 -> 包 -> npm(运行 npm 命令)

并将install添加为命令,并将web-project 的根目录添加为工作目录

否则,请尝试添加以下功能:

node.js | C:\Program Files\nodejs\node.exe

和:

   npm | C:\Program Files\nodejs\npm.cmd
于 2016-01-25T16:02:19.007 回答