【问题标题】:Grunt integration with Jenkins on windows issue在 Windows 问题上与 Jenkins 的 Grunt 集成
【发布时间】:2023-03-23 10:53:01
【问题描述】:

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

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

正如其他帖子 Jenkins integration with Grunt 中所建议的那样,我已经多次重新启动我的 jenkins,并尝试处理该帖子中写的所有答案,但仍然显示错误,grunt: command not found。

来自 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 中的所有模块,之后在所有其他构建中显示上述输出。

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

【问题讨论】:

    标签: jenkins gruntjs


    【解决方案1】:

    经过大量搜索,我找到了我的 grunt 的安装位置。就 jenkins 构建而言,它安装在 drive:/.jenkins....../workspace/node_modules/.bin

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 它不存在于路径变量中,因为 grunt 不是全局安装的,而是每个项目的本地安装。它甚至在我的本地系统环境变量上也不可用,但我仍然可以在我的特定项目中使用 grunt 执行所有任务。
      • 我已经编辑并在我的问题中包含了 env 路径。
      • 在哪里可以找到 grunt_path,因为我在项目文件夹中运行了 npm install。
      猜你喜欢
      • 2014-03-12
      • 2014-08-06
      • 1970-01-01
      • 1970-01-01
      • 2018-08-07
      • 2018-05-05
      • 2016-09-17
      • 2016-09-16
      • 2012-11-16
      相关资源
      最近更新 更多