node.js 如何从詹金斯运行 npm/grunt 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25919364/
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
how to run npm/grunt command from jenkins
提问by Simple-Solution
I'm new to this area and was trying to run the following commands from jenkins:
我是这个领域的新手,并试图从 jenkins 运行以下命令:
npm install
grunt quickStart
So far I've a jenkins running on a window machine as a window service and I've also installed NodeJs plugin for jenkins.
到目前为止,我已经在窗口机器上运行了一个 jenkins 作为窗口服务,并且我还为 jenkins 安装了 NodeJs 插件。
However, I'm stuck and quit confused following instructions here, its asking me to to add one or mode nodeJs installation and I could not find those setting and not even sure if I even need them in the first place.
但是,我被卡住了,并按照此处的说明退出了困惑,它要求我添加一个或模式 nodeJs 安装,但我找不到这些设置,甚至不确定我是否一开始就需要它们。
Here is the bit that's asking me to do:

这是要求我做的一点:

I cannot see this setting for the jenkins job I create. Is there an easy way to run those command in jenkins from a .bator .shscript, a .batwould be recomended since I'm on window machine.
我无法看到我创建的 jenkins 作业的此设置。有没有一种简单的方法可以从 a.bat或.sh脚本在 jenkins 中运行这些命令,.bat因为我在窗口机器上,所以推荐a 。
Note : I've already checked out a project using git in jenkins!!!
注意:我已经在 jenkins 中使用 git 签出了一个项目!!!
Thanks
谢谢
采纳答案by yokodev
"its asking me to to add one or mode nodeJs installation and I could not find those setting and not even sure if I even need them in the first place."
I don't think you need that I have pointed jenkins to the node installation folder an nothing more.., for this you go to Manage Jenkins->Configure System->NodeJS->NodeJS installations.. type in any name you like and point to where the node home folder is.
“它要求我添加一个或模式 nodeJs 安装,但我找不到这些设置,甚至不确定我是否一开始就需要它们。”
我认为您不需要我将 jenkins 指向节点安装文件夹仅此而已..,为此,您转到管理 Jenkins->配置系统->NodeJS->NodeJS 安装.. 输入您喜欢的任何名称并指向节点主文件夹所在的位置。
...cannot see this setting for the jenkins job I create...
...无法看到我创建的 jenkins 作业的此设置...
Once you have configure that in your jenkins configuration you should have that configuration available like so:
一旦您在 jenkins 配置中进行了配置,您应该可以像这样使用该配置:


...Is there an easy way to run those command in jenkins from a .bat or .sh script, a .bat would be recomended since I'm on window machine
I'm sorry don't get what commands are you referring to...
so summarizing :
...是否有一种简单的方法可以从 .bat 或 .sh 脚本在 jenkins 中运行这些命令,建议使用 .bat,因为我在窗口机器上
很抱歉不明白你指的是什么命令……总结一下:
- you have to tell jenkins where you have your node installation
- use that configuration in your jobs
- 你必须告诉詹金斯你的节点安装在哪里
- 在您的工作中使用该配置
hope this helps...
希望这可以帮助...
回答by PyTux
The way I made it, was trough execute shell, as the build tool for nodejs is npm, I simply wrote a shell script that instructs jenkins to run npm install in the workspace directory inside jenkins where it clones the git repository and then to zip and move the package if successful to another folder.
我的方法是通过执行 shell,因为 nodejs 的构建工具是 npm,我只是编写了一个 shell 脚本,指示 jenkins 在 jenkins 内的工作区目录中运行 npm install,在那里它克隆 git 存储库,然后压缩和如果成功,将包移动到另一个文件夹。

