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:41

This was a weird and very annoying bug, but I finally found a workaround. In the %AppData%\Roaming\npm directory, there are two files: "grunt" and "grunt.cmd". "grunt" is a unix file, and "grunt.cmd" is supposed to run the grunt-cli application using node, but it doesn't. I had to create a new file called "grunt.bat" (which takes precedence over "grunt.cmd") that contains

node "%~dp0\node_modules\grunt-cli\bin\grunt" %*

Now it works. Not sure why.

查看更多
戒情不戒烟
3楼-- · 2019-02-01 20:42

Here is a complement to Christopher's answer (I don't have enough reputation to make a comment).

In case you don't want to create a user on build server, you can write full path to execute a npm package. Here is a command line runner to run Weyland without creating dedicated user on build server:

  • Command executable: "C:\Program Files\nodejs\node.exe"
  • Command parameters: c:\users\Administrator\AppData\Roaming\npm\node_modules\weyland\bin\cli.js build

BTW, it seems that the installer of Node.js has another solution. Unfortunately, it's trimmed!

Here is the screenshot of Node.js installer:

查看更多
成全新的幸福
4楼-- · 2019-02-01 20:46

make sure %AppData%\Roaming\npm path is on you windows GLOBAL path variable, restart team agent service and will work

查看更多
该账号已被封号
5楼-- · 2019-02-01 20:49

I ran into the same problem when trying to get grunt to work with TFS where it would be ran by the tfsservice user. Running our builds as a different user as Christopher's answer suggests wasn't an option for us. After I added C:\Users\tfsservice\AppData\Roaming\npm to the tfsservice user's Path it was able to find the grunt-cli when I manually logged in as tfsservice, but not when the TFS Build agent performed the build. At first I just changed my build process to use the full path to the grunt.cmd file.

So I changed from using this:

grunt deploy

to using this:

"C:\Users\tfsservice\AppData\Roaming\npm\grunt.cmd" deploy

I imagine doing the same for your Team City user would also fix the problem. Of course if you do this you have to make sure that the grunt-cli is installed in the same location on all of your build servers.

Turns out though that I had just missed the final step of restarting my PC (so that the tfsservice would get restarted) and then the builds were able to find grunt without specifying the full path.

I assume that the trimmed node.js installer description shown by Zeke Lu's answer was going to say that other users need to update their Path environment variable.

查看更多
贪生不怕死
6楼-- · 2019-02-01 20:51

You should restart the TeamCity Build Agents after installing NPM.

查看更多
\"骚年 ilove
7楼-- · 2019-02-01 20:52

I know this question is kind of old. But I struggled with the same problem nowadays and couldn't find a solution... but finally I did. Here you are.

TeamCity build steps should include:

1) Installation grunt-cli Command Line Command: npm install grunt-cli

2) Running grunt build task Command Line Command: node "node_modules/grunt-cli/bin/grunt" build

Working directory for both cases should be where your grountfile.js is located.

查看更多
登录 后发表回答