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)

Community
  • 1
  • 1
sethreidnz
  • 665
  • 6
  • 19

3 Answers3

8

The solution to this was to install node.js with the regular installer :

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

This then worked. Still have other issues but the direct issue in this question is solved by not using nvm to install node. I could then add an npm task in the VSO build definition interface.

sethreidnz
  • 665
  • 6
  • 19
  • 3
    You will need to restart the agent service (it will be called `VSTS Agent` under services.msc), or if running the agent interactively just restart it. – Simon_Weaver May 20 '17 at 03:15
3

Make sure the npm is installed in "C:\Program Files\nodejs\" folder, and then add following in your PowerShell script:

$env:Path += ";C:\Program Files\nodejs\"
Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
  • Thanks for that but same error. I can run (when remotely accessing the server) npm from that folder when logged in as the account that was generated when I created the server. When I installed the VSO agent I could not use those credentials (would not work and gave me errors) so chose the "default service account". The account the command line installer does by default. As the actual user I remote in as everything works fine. When running script from VSO build it doesnt.. any other ideas? Thanks again – sethreidnz Jan 26 '16 at 10:30
  • @justsayno So the build agent is running with network service account. It seems that nvm doesn't install the npm globally for all users. Check if the nodejs is installed in this path: "C:\Users\UserName\AppData\Roaming\nvm\NodeJSVersion". If yes, try to use this path to see if it works. – Eddie Chen - MSFT Jan 26 '16 at 10:43
  • No Luck... How would I log in as the network service account? Or better still just make the VSO agent use the default account created by Azure i,e, the one that the script works for... Sorry if these are dumb questions I'm not much of a network/sys admin guy! FYI I am using nvm becuase I found it was the only way to easily manage upgrading nodejs on Windows. I could presumably install node globally with the regular installer on this server? – sethreidnz Jan 26 '16 at 10:49
  • @justsayno when you configure the agent you have the option of specifying the username and password for the account you want to configure the service under. Network Service is simply the default. – Chris Patterson Feb 11 '16 at 14:46
  • @ChrisPatterson I tried that but it would give me errors when I did anything but use the default settings – sethreidnz Mar 21 '16 at 22:40
  • What errors did you get? Did you make sure the user you used has permission to run as a service. – Chris Patterson Mar 21 '16 at 22:49
1

Try adding the run npm command build task from:

Add build step -> Add tasks -> Package -> npm (run a npm command)

And add install as command, and the root of the web-project as working directory

Otherwise, try adding the following capabilities:

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

and:

   npm | C:\Program Files\nodejs\npm.cmd
Dienér
  • 109
  • 1
  • 9
  • Still no luck with either option... Do you know if there is some way to access to PATH variable of the service user? – sethreidnz Jan 25 '16 at 19:33
  • 3
    TIP: Make sure to restart the VSOagent service if you have it installed as a service, in order for the PATH update to be registered on the build. – TetraDev Jun 13 '16 at 21:24
  • @TetraDev after installing NodeJS and restarting the service our agents picked up the new capabilities, thanks! – Novastorm Feb 13 '17 at 16:47