Upen
Upen

Reputation: 1438

Running nodejs using maven exec plugin in Jenkins

I have node, npm and grunt installed on my jenkins box. I am able to successfully run the below commands using execute shell in pre steps in Jenkins.

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

As the next step when I call mvn clean package, Build fails with the error

./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.

I don't have root access on this Linux box. Maven exec plugin, is failing the build. Plugin definition in pom below.

 <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

I cant do a symlink to point node installation to /usr/bin. Any work around to solve this issue?

Upvotes: 2

Views: 6215

Answers (1)

am80l
am80l

Reputation: 1531

I ran into a lot of problems trying to use the exec-maven-plugin. In my experience, the frontend-maven-plugin is far and away the best plugin for this type of build/deploy process. It will download/install Node and NPM locally, run NPM install, Grunt, Gulp and/or Karma. Since my build servers have very strict limitations on reaching outside the network during build, I commit the server version of node and any node packages I use with grunt.

<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>

One thing to be aware of it is will download node for the system it is being run on, so if you have a different OS on your build server, you'll need to make sure that is the version you have checked into version control, your local version (for me OSX) will have to be maintained local to your project. There is discussion of using the frontend-maven-plugin with Grunt on this StackOverflow thread: "Is it possible to compile grunt project from maven?"

Upvotes: 2

Related Questions