在 windows 问题上与 Jenkins 的 Grunt 集成

Grunt integration with Jenkins on windows issue

我是 运行 Jenkins on Tomcat7 - Windows 7. 我在我的 jenkins 配置中提供了节点 bin 路径。然后运行一个shell脚本如下:

echo $PATH
node --version
npm install -g grunt-cli
npm install
grunt cssmin

按照其他 post Jenkins integration with Grunt 中的建议,我已经多次重启我的 jenkins,并尝试处理写在 post 中的所有答案,但它仍然显示错误,咕噜声:找不到命令。

来自 jenkins 控制台输出的错误堆栈跟踪:

/c/apache-maven-3.2.5/bin:/c/Program Files/Java/jdk1.7.0_79/bin:/c/Program Files/nodejs/bin:/c/Program Files/Java/jdk1.7.0_79/bin:/c/Program Files/nodejs/:

+ node --version
v0.10.30
+ npm install -g grunt-cli
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm\grunt -> C:\Windows\system32\config\systemprofile\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt
grunt-cli@0.1.13 C:\Windows\system32\config\systemprofile\AppData\Roaming\npm\node_modules\grunt-cli
├── resolve@0.3.1
├── nopt@1.0.10 (abbrev@1.0.7)
└── findup-sync@0.1.3 (lodash@2.4.2, glob@3.2.11)
+ npm install
npm WARN package.json Trademust@1.0.0 No repository field.
+ grunt cssmin
C:\Program Files\Apache Software Foundation\Tomcat 7.0\temp\hudson2968878175697925824.sh: line 6: grunt: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

我也遵循了本网站提到的步骤grunt-on-jenkins

package.json 和 Gruntfile.js 在我第一次执行 jenkins 构建时位于根目录中,grunt 安装了我的 gruntfile.js 中的所有模块,之后在所有其他构建中它显示了上面的输出。

任何人都可以检查这里发生了什么问题。

从错误信息来看,sheel 是找不到grunt 的。您能否检查它是否存在于 $PATH 变量中。这个 shell 脚本是 运行 在哪个节点上?您可以检查特定节点的 $PATH。您还可以在 shell 脚本期间将 grunt 安装路径添加到 $PATH 变量。

grunt_path="grunt_installtion_path"
export PATH=${PATH}:${grunt_path}

找了很多,终于找到我的grunt安装位置了。就 jenkins build 而言,它安装在 drive:/.jenkins....../workspace/node_modules/.bin.

在使用 shell 脚本 export path=$PATH:drive:/.jenkins....../workspace/node_modules/.bin 在 jenkins 中提供此路径后,grunt 开始执行。

此外,我在此过程中学到的是检查可执行文件在系统路径上的可用位置,或者 jenkins 引用的路径是使用 which "executable_name" 而不带引号。您可以在 windows 和 linux 上使用此命令。例如:which grunt 将显示存在 grunt 可执行文件的路径。