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)

3
  • What error message do you get when queue a build with npm task? Commented Jan 26, 2016 at 3:15
  • @Eddie-MSFT added the error message to my question Commented Jan 26, 2016 at 3:55
  • 2
    I just had this very issue. Turns out that the Agent will pick up node and npm as capabilities automatically if you restart the Agent service. There is no need to add them manually. Commented Sep 5, 2016 at 4:03

4 Answers 4

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
NVM does work with private Azure agents, we are using it, though this is 7 years after your post so something may have been resolved)
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\"

6 Comments

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
@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.
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?
@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.
@ChrisPatterson I tried that but it would give me errors when I did anything but use the default settings
|
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

3 Comments

Still no luck with either option... Do you know if there is some way to access to PATH variable of the service user?
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 after installing NodeJS and restarting the service our agents picked up the new capabilities, thanks!
0

In my case, I had installed the agent before installing Node + npm. The solution was to uninstall the agent and reconfigure it from scratch

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.