linux - 在Jenkins中使用maven exec插件运行nodejs

标签 linux node.js maven jenkins gruntjs

我的 jenkins 盒子上安装了 node、npm 和 grunt。我能够在 Jenkins 的预处理步骤中使用执行 shell 成功运行以下命令。

PATH=$PATH:/sev/installed/node-v0.10.31/bin
rm -rf node_modules
rm -rf bower_components
npm install --python=/sev/installed/Python-2.7.3/bin/python
npm update --python=/sev/installed/Python-2.7.3/bin/python
bower install
bower update

下一步当我调用 mvn clean package 时,构建失败并出现错误

./usr/bin/env: node: No such file or directory
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.973s
[INFO] Finished at: Tue Aug 26 23:51:16 GMT+00:00 2014
[INFO] Final Memory: 17M/438M
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default) on project TestUI: Command execution failed. Process exited with an error: 127 (Exit value: 127) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

我没有此 Linux 机器的 root 访问权限。 Maven exec 插件构建失败。下面pom中的插件定义。

 <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <goals>
                <goal>exec</goal>
            </goals>
            <phase>prepare-package</phase>
        </execution>
    </executions>
        <configuration>
            <executable>${project.basedir}/node_modules/grunt-cli/bin/grunt</executable>
            <workingDirectory>${project.basedir}</workingDirectory>
        </configuration>
    </plugin

我无法创建符号链接(symbolic link)将 Node 安装指向/usr/bin。有什么办法可以解决这个问题吗?

最佳答案

我在尝试使用exec-maven-plugin时遇到了很多问题。根据我的经验,frontend-maven-plugin无疑是此类构建/部署过程的最佳插件。它将在本地下载/安装 Node 和 NPM,运行 NPM install、Grunt、Gulp 和/或 Karma。由于我的构建服务器在构建期间对访问网络外部有非常严格的限制,因此我提交了 Node 的服务器版本以及与 grunt 一起使用的任何 Node 包。

<plugin>
    <groupId>com.github.eirslett</groupId>
    <artifactId>frontend-maven-plugin</artifactId>
    <version>...</version>

    <!-- optional -->
    <configuration>
        <workingDirectory>src/main/frontend</workingDirectory>
    </configuration>

   <execution>
    <id>grunt build</id>
    <goals>
        <goal>grunt</goal>
    </goals>

    <!-- optional: the default phase is "generate-resources" -->
    <phase>generate-resources</phase>

    <configuration>
        <!-- optional: if not specified, it will run Grunt's default
        task (and you can remove this whole <configuration> section.) -->
        <arguments>build</arguments>
    </configuration>
</execution>
</plugin>

需要注意的一件事是,它将下载正在运行的系统的 Node ,因此,如果您的构建服务器上有不同的操作系统,则需要确保这是您已 checkin 的版本版本控制,您的本地版本(对我来说 OSX)必须维护在您的项目本地。在这个 StackOverflow 线程上讨论了将 frontend-maven-plugin 与 Grunt 结合使用:“ Is it possible to compile grunt project from maven?

关于linux - 在Jenkins中使用maven exec插件运行nodejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25516963/

相关文章:

linux - 如何从命令任务传递加密密码以执行脚本以调用 pmrep

linux - 将最后一个命令状态传递给 $PS1 函数

linux - 用于在特定文件夹中查找文件并基于文件的 "age"的 Shell 脚本

javascript - 我想使用 node.js 将图像上传到我的博客

linux - Linux 文件系统是否有效地缓存文件?

php - 推送通知服务,如 ios facebook 应用程序

javascript - 无法从 VUE 向 ESP32 https 服务器发出 POST 请求

git - 停止 mvn release 触发重复 Jenkins 构建

maven - 开普勒中的生命周期未涵盖 aspectj-maven-plugin

java - 在 Eclipse 的 Maven Dependencies 文件夹中按文本搜索文件