Search code examples
node.jstfsaurelia

TFS 2017 on-premise cannot find node modules in cmd


How to run npm modules in tfs agent running as a service?

Here's my setup.

I setup agent on local machine with TFS 2017 running on-premise. And I try to build aurelia application on agent running as a service. I already have installed node, aurelia cli and npm in machine where the agent run. It was globally accessed running manually cmd with command au build(aurelia cli build). However when I create a Command Line build step running au(Tool) and build(Arguments) the agent does not find au.

I think it will also not find other npm modules.


Solution

  • In general, the build agent (running as service) uses Network Service account and the installed npm packages are in current user folder, so you can call au command directly, but can’t call au command during the build.

    You can change build agent service account to use your account or refer to these steps to install Aurelia-cli package and call au command in Command Line step if you still uses Network Service account:

    1. Add Command line step to build definition (Tool: npm; Arguments: install Aurelia-cli -g)
    2. Add Command line step (Tool: C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\npm\au; Arguments: build; Working folder: [project folder] (e.g. $(Build.SourcesDirectory))

    Note: the step 1 just need to run only once, you can disable or delete it for next build to save time.

    On the other hand, you can try to add C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\npm to environment variable (system variables > Path), then use au directly.