TeamCity build runner not recognizing executable

2019-02-01 20:26发布

I'm trying to run a simple gruntfile.js as part of my build in TeamCity. However, even after installing grunt and grunt-cli as global node packages, TeamCity still won't recognize them. I can type grunt in the command line and it works, but when I run it in TeamCity either through a command line runner or an executable with parameters, it still gives

'grunt' is not recognized as an internal or external command

I also tried installing TeamCity.Node, which is a plugin for running grunt scripts, but it can't find grunt either. Any ideas?

8条回答
老娘就宠你
2楼-- · 2019-02-01 20:52

You don't need to change TeamCity account from system to local like Christoper wrote. It's simpler way:

1.[build agent machine] Make sure you have node directory and local npm packages directory in your PATH, example:

 C:\Users\'yourUserName'\AppData\Roaming\npm;C:\Program Files\nodejs 
  1. [build agent machine] Install grunt globally: npm install grunt-cli
  2. [build step] Run cmd in your project dirctory: npm install -g grunt-cli. You can do this step only once (on your local machine) and commit file changes to repo
  3. [build step] Run cmd in your project dirctory: npm install
  4. [build step] Run grunt build as powershell script: powershell -Command "grunt build"

In some reason build agent running on system account cant get access to C:\Users\'yourUserName'\AppData\Roaming\npm via cmd, but via powershell can.

查看更多
疯言疯语
3楼-- · 2019-02-01 21:06

I couldn't get the accepted solution to work. The problem for me was that TeamCity services (server and agent) were running under system accounts. AFAIK, there is no concept of "globally install npm package for all users of the OS". So I:

  1. created a TeamCity windows user
  2. changed the TeamCity services to run as that user
  3. logged into the OS as the TeamCity user
  4. ran npm install -g grunt-cli
  5. restarted the services.

From there, the NodeJS, NPM and Grunt tasks just started working.

查看更多
登录 后发表回答