node.js Jenkins 与 Grunt 的集成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21765428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jenkins integration with Grunt
提问by tempid
I've setup Jenkins v1.550 on Windows Server 2008 R2. It runs as a service at http://localhost:8080for now. I'm logged into the machine as an Administrator. I've installed Node.js and can run "npm" from the command line.
我已经在 Windows Server 2008 R2 上设置了 Jenkins v1.550。它http://localhost:8080现在作为服务运行。我以管理员身份登录机器。我已经安装了 Node.js 并且可以从命令行运行“npm”。
I've also installed the NodeJS plugin v0.2.1 for Jenkins. I then went into the Configure System section of Jenkins, scrolled down to NodeJS installations, clicked on Add NodeJS button, gave "NodeJS" as the name, and "C:\Program Files\nodejs" as the path to the installation directory. I didn't check the "Install automatically" option as I read on the plugin page that it is only available to Linux.
我还为 Jenkins 安装了 NodeJS 插件 v0.2.1。然后我进入 Jenkins 的“配置系统”部分,向下滚动到 NodeJS 安装,单击“添加 NodeJS”按钮,将“NodeJS”作为名称,“C:\Program Files\nodejs”作为安装目录的路径。当我在插件页面上阅读它仅适用于 Linux 时,我没有选中“自动安装”选项。
I then created a new job, clicked the checkbox that said "Provide Node & npm bin/ folder to PATH", created a new build step for "Execute Windows batch command" and typed in "node --version" and "grunt --version" and saved it.
然后我创建了一个新作业,单击了“提供节点和 npm bin/ 文件夹到 PATH”的复选框,为“执行 Windows 批处理命令”创建了一个新的构建步骤,并输入了“node --version”和“grunt --”版本”并保存。
I ran the job and this is the output -
我运行了这项工作,这是输出 -
Building in workspace C:\Program Files (x86)\Jenkins\workspace\Test_1.0
[Test_1.0] $ cmd /c call C:\Windows\TEMP\hudson1381541243088903083.bat
C:\Program Files (x86)\Jenkins\workspace\Test_1.0>node --version
v0.10.24
C:\Program Files (x86)\Jenkins\workspace\Test_1.0>grunt --version
'grunt' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files (x86)\Jenkins\workspace\Test_1.0>exit 9009
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
It looks like it's unable to find the grunt-cli for the user account Jenkins is running under (System). I tried to installing grunt cli globally (npm install -g grunt-cli) and also grunt locally (npm install grunt). No luck.
似乎无法找到 Jenkins 在(系统)下运行的用户帐户的 grunt-cli。我尝试在全局安装 grunt cli ( npm install -g grunt-cli) 并在本地安装 grunt ( npm install grunt)。没运气。
Can someone please help?
有人可以帮忙吗?
回答by aqm
for nice easy to configure self-installed nodejs on the machine, i have to recommend the excellent -> http://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
为了在机器上轻松配置自安装的 nodejs,我必须推荐优秀的 -> http://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
it will install nodejs and grunt on the machine, through easy to use web front end no shell required
它将在机器上安装 nodejs 和 grunt,通过易于使用的 web 前端不需要 shell
jenkins jobs can then simply run nodejs build steps, hey presto
jenkins 工作然后可以简单地运行 nodejs 构建步骤,嘿presto
steps involved :
涉及的步骤:
a) install this on your jenkins instance -> http://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
a) 在您的 jenkins 实例上安装它 -> http://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
b) create a nodejs installation on jenkins
b) 在 jenkins 上创建 nodejs 安装
go to
去
http://URL_OF_JENKINS/jenkins/configure
- NodeJS- > NodeJS installations -> Add NodeJS -> Name = "NodeJS 0.11.10", tick "Install automatically", select "Install from nodejs.org", add "grunt-cli" to globally installed packages
- NodeJS-> NodeJS installations -> Add NodeJS -> Name = "NodeJS 0.11.10",勾选"Install automatically",选择"Install from nodejs.org",在全局安装的包中添加"grunt-cli"
c) create a job with "execute NodeJS script" build task
c) 使用“执行 NodeJS 脚本”构建任务创建作业
var sys = require('sys');
sys.puts('NodeJS Test');
sys.puts('***************');
sys.puts('helloworld');
volia :)
沃利亚 :)
run the job and see the nodejs script run,
运行作业并查看运行的 nodejs 脚本,
from their the world is your oyster you can use grunt by ticking "Provide Node/npm bin folder to PATH" and running a "execute shell" build task
从他们的世界是你的牡蛎你可以通过勾选“提供节点/npm bin文件夹到PATH”并运行“执行shell”构建任务来使用grunt
npm update
grunt
grunt --force reporting
回答by Andrew Bullock
You will need to restart the Jenkins service after installing node, presumably to cause it to refresh its cached copy of your PATHenvironment variable
安装节点后,您将需要重新启动 Jenkins 服务,大概是为了使其刷新PATH环境变量的缓存副本
回答by Stuart
I have grunt doing some tasks for me in Jenkins, but I went the npm script route. Grunt and grunt-cli are dev dependencies, and I have the following defined in my package.json file:
我在 Jenkins 中为我做了一些任务,但我选择了 npm 脚本路线。Grunt 和 grunt-cli 是开发依赖项,我在 package.json 文件中定义了以下内容:
"scripts": {
"test": "node node_modules/grunt-cli/bin/grunt test"
},
In Jenkins (running on Windows), I added two post-build tasks:
在 Jenkins(在 Windows 上运行)中,我添加了两个构建后任务:
npm install
npm test
We just installed NodeJs normally on the Jenkins server.
我们只是在 Jenkins 服务器上正常安装了 NodeJs。
回答by user3114859
Another solution that worked for me on Windows is to use the full path to the grunt exec file, which can be found by writing "where grunt" in the command shell. I used the full path in the regular bat-file.
在 Windows 上对我有用的另一个解决方案是使用 grunt exec 文件的完整路径,可以通过在命令外壳中写入“where grunt”来找到它。我使用了常规 bat 文件中的完整路径。
回答by vanval
Had the same issue on Windows. When I manually installed node and ran npm install -g grunt-cli from command line, jenkins could not recognize the grunt command. So uninstall node, reinstall it but dont run npm install. Then restart the jenkins slave. Then from the jenkins job that runs on your specific jenkins slave, make it run a Windows batch command that runs npm install -g grunt-cliAfter that again restart the jenkins service. Then from the job run npm install. Then everything worked for me. If issues still persist, then uninstall the slave, and reinstall it, then everything works fine immediately.
在 Windows 上有同样的问题。当我手动安装 node 并从命令行运行 npm install -g grunt-cli 时,jenkins 无法识别 grunt 命令。所以卸载节点,重新安装它但不要运行 npm install。然后重启詹金斯奴隶。然后从在您的特定 jenkins slave 上运行的 jenkins 作业,让它运行运行npm install -g grunt-cli的 Windows 批处理命令,然后再次重新启动 jenkins 服务。然后从作业运行npm install。然后一切都对我有用。如果问题仍然存在,则卸载从站,然后重新安装它,然后一切都会立即正常工作。

