allegro/grunt-maven-plugin

Cannot run program "npm" - Jenkins Linux Agent

Opened this issue · 4 comments

Hi,

I am having a jenkins linux agent where I am trying to build a web application having front end resources managed by npm-grunt-bower combination and the build happens with the help of grunt-maven-plugin. The application is getting built by maven fine in my intelliJ IDE but when I am building it in server it throws below error:

[ERROR] Failed to execute goal pl.allegro:grunt-maven-plugin:1.5.1:npm (default) on project >corporate: Unable to execute mojo: Command execution failed. Cannot run program "npm" (in >directory "/home/ec2-user/jenkins/workspace/XXXX/target/grunt"): >error=2, No such file or directory

Initially I thought its unable to find npm executable so added a pre-build step to execute 'npm -version' as shell command which executes fine as shown below:

[XXXX] $ /bin/sh -xe /tmp/hudson1866832324925162231.sh

  • npm -version
    2.11.3

Please can you suggest where the problem is? Here is my plugin configuration in pom.xml:

            <plugin>
                <groupId>pl.allegro</groupId>
                <artifactId>grunt-maven-plugin</artifactId>
                <version>1.5.1</version>
                <configuration>
                    <jsSourceDirectory>.</jsSourceDirectory>
                    <sourceDirectory>src/main/</sourceDirectory>
                    <gruntOptions>
                        <gruntOption>--verbose</gruntOption>
                    </gruntOptions>
                    <npmEnvironmentVar>
                        <PHANTOMJS_CDNURL>https://cnpmjs.org/downloads</PHANTOMJS_CDNURL>
                    </npmEnvironmentVar>
                    <filteredResources>
                        <filteredResource>maven-properties.json</filteredResource>
                    </filteredResources>
                    <gruntBuildDirectory>${basedir}/target/grunt</gruntBuildDirectory>
                    <target>build</target>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>clean</goal>
                            <goal>create-resources</goal>
                            <goal>npm</goal>
                            <goal>bower</goal>
                            <goal>grunt</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Hm, is there no more info? Could you run Maven in debug mode to see some more?

Hey,
Even I am facing the same issue on Jenkins build when I try maven deploy command.
The error is like this :

Failed to execute goal pl.allegro:grunt-maven-plugin:1.4.1:npm (default) on project alarm-dashboard: Unable to execute mojo: Command execution failed. Cannot run program "npm" (in directory "/home/dwx/jenkins/workspace/AVD_Phase1/alarm-dashboard-war/AlarmDashboard/target-grunt"): error=2, No such file or directory ->

In local eclipse it seems to works fine. I have only these below entries in pom.xml.

Can anyone help me resolve this?

<plugin>
<groupId>pl.allegro</groupId>
      <artifactId>grunt-maven-plugin</artifactId>
      <version>1.4.1</version>
      <executions>
        <execution>
          <goals>
            <goal>npm</goal>
            <goal>grunt</goal>
          </goals>
        </execution>
      </executions>
    </plugin>

And this is my GruntFile

module.exports = function(grunt) {
	grunt.loadNpmTasks('grunt-contrib-uglify');
  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify: {
    	core: {
            files: [{
              expand: true,
              cwd: 'src/main/webapp',
              src: 'js/*.js',
              dest: "src/main/webapp/build",
              ext: '.min.js'
            }]
    	}
    },
  });

  grunt.registerTask('default', ['uglify']);

};

I have a similar issue on using exec-maven-plugin on my mac. Could you give me a hand ? Here is the link : https://stackoverflow.com/questions/51384032/exec-maven-plugin-plugin-error/51786123#51786123