frontend-maven-plugin icon indicating copy to clipboard operation
frontend-maven-plugin copied to clipboard

Problem using the plugin inside a Continuous Integration pipeline (Bitbucket pipeline)

Open trisquel87 opened this issue 5 years ago • 11 comments

Hello,

we have a problem using the plugin (v1.9.1 or any other) in Bitbucket pipelines.

We have this pipeline:

pipelines:
    default:
    - step:
          name: Package
          image: maven:3.5-jdk-8-alpine
          caches:
          - maven
          script:
          - mvn install -X
          - mvn clean package -P environment=production
          artifacts:
          - target/*.war

The error that we have is:

+ mvn install -X
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T18:33:14Z)
Maven home: /usr/share/maven
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8-openjdk/jre 
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.19.78-coreos", arch: "amd64", family: "unix"
...
[DEBUG] Configuring mojo com.github.eirslett:frontend-maven-plugin:1.9.1:install-node-and-npm from plugin realm ClassRealm[plugin>com.github.eirslett:frontend-maven-plugin:1.9.1, parent: sun.misc.Launcher$AppClassLoader@70dea4e]
[DEBUG] Configuring mojo 'com.github.eirslett:frontend-maven-plugin:1.9.1:install-node-and-npm' with basic configurator -->
[DEBUG]   (f) installDirectory = /opt/atlassian/pipelines/agent/build/alert-web/target
[DEBUG]   (f) nodeDownloadRoot = https://nodejs.org/dist/
[DEBUG]   (f) nodeVersion = v10.9.0
[DEBUG]   (f) npmDownloadRoot = https://registry.npmjs.org/npm/-/
[DEBUG]   (f) npmVersion = provided
[DEBUG]   (f) project = MavenProject: es.company.alert:alert-web:1.0.0 @ /opt/atlassian/pipelines/agent/build/alert-web/pom.xml
[DEBUG]   (f) repositorySystemSession = org.eclipse.aether.DefaultRepositorySystemSession@63124c8b
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@d1d8e1a
[DEBUG]   (f) skipTests = false
[DEBUG]   (f) testFailureIgnore = false
[DEBUG]   (f) workingDirectory = /opt/atlassian/pipelines/agent/build/alert-web/src/main/resources/static/resources
[DEBUG]   (f) execution = com.github.eirslett:frontend-maven-plugin:1.9.1:install-node-and-npm {execution: install node and npm}
[DEBUG] -- end configuration --
[INFO] Installing node version v10.9.0
[DEBUG] Creating install directory /opt/atlassian/pipelines/agent/build/alert-web/target/node
[DEBUG] Creating temporary directory /opt/atlassian/pipelines/agent/build/alert-web/target/node/tmp
[INFO] Downloading https://nodejs.org/dist/v10.9.0/node-v10.9.0-linux-x64.tar.gz to /root/.m2/repository/com/github/eirslett/node/10.9.0/node-10.9.0-linux-x64.tar.gz
[INFO] No proxies configured
[INFO] No proxy was configured, downloading directly
[INFO] Unpacking /root/.m2/repository/com/github/eirslett/node/10.9.0/node-10.9.0-linux-x64.tar.gz into /opt/atlassian/pipelines/agent/build/alert-web/target/node/tmp
[INFO] Copying node binary from /opt/atlassian/pipelines/agent/build/alert-web/target/node/tmp/node-v10.9.0-linux-x64/bin/node to /opt/atlassian/pipelines/agent/build/alert-web/target/node/node
[INFO] Extracting NPM
[DEBUG] Deleting temporary directory /opt/atlassian/pipelines/agent/build/alert-web/target/node/tmp
[INFO] Installed node locally.
[INFO] 
[INFO] --- frontend-maven-plugin:1.9.1:npm (npm install) @ alert-web ---
[DEBUG] Configuring mojo com.github.eirslett:frontend-maven-plugin:1.9.1:npm from plugin realm ClassRealm[plugin>com.github.eirslett:frontend-maven-plugin:1.9.1, parent: sun.misc.Launcher$AppClassLoader@70dea4e]
[DEBUG] Configuring mojo 'com.github.eirslett:frontend-maven-plugin:1.9.1:npm' with basic configurator -->
[DEBUG]   (f) arguments = install --no-optional
[DEBUG]   (f) installDirectory = /opt/atlassian/pipelines/agent/build/alert-web/target
[DEBUG]   (f) npmInheritsProxyConfigFromMaven = true
[DEBUG]   (f) project = MavenProject: es.company.alert:alert-web:1.0.0 @ /opt/atlassian/pipelines/agent/build/alert-web/pom.xml
[DEBUG]   (f) repositorySystemSession = org.eclipse.aether.DefaultRepositorySystemSession@63124c8b
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@d1d8e1a
[DEBUG]   (f) skipTests = false
[DEBUG]   (f) testFailureIgnore = false
[DEBUG]   (f) workingDirectory = /opt/atlassian/pipelines/agent/build/alert-web/src/main/resources/static/resources
[DEBUG]   (f) execution = com.github.eirslett:frontend-maven-plugin:1.9.1:npm {execution: npm install}
[DEBUG] -- end configuration --
[INFO] Running 'npm install --no-optional' in /opt/atlassian/pipelines/agent/build/alert-web/src/main/resources/static/resources
[DEBUG] Executing command line [/opt/atlassian/pipelines/agent/build/alert-web/target/node/node, /opt/atlassian/pipelines/agent/build/alert-web/target/node/node_modules/npm/bin/npm-cli.js, install, --no-optional]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] alert 1.0.0 ........................................ SUCCESS [  0.938 s]
[INFO] alert-util ......................................... SUCCESS [ 39.543 s]
[INFO] alert-business ...................................... SUCCESS [ 27.176 s]
[INFO] alert-web 1.0.0 .................................... FAILURE [  5.100 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:14 min
[INFO] Finished at: 2020-01-13T15:27:59Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.9.1:npm (npm install) on project alert-web: Failed to run task: 'npm install --no-optional' failed. 
java.io.IOException: Cannot run program "/opt/atlassian/pipelines/agent/build/alert-web/target/node/node" (in directory "/opt/atlassian/pipelines/agent/build/alert-web/src/main/resources/static/resources"): error=2, No such file or directory -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.9.1:npm (npm install) on project alert-web: Failed to run task
...
Caused by: org.apache.maven.plugin.MojoFailureException: Failed to run task
...
Caused by: com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException: 'npm install --no-optional' failed.
...
Caused by: com.github.eirslett.maven.plugins.frontend.lib.ProcessExecutionException: java.io.IOException: Cannot run program "/opt/atlassian/pipelines/agent/build/alert-web/target/node/node" (in directory "/opt/atlassian/pipelines/agent/build/alert-web/src/main/resources/static/resources"): error=2, No such file or directory
...
Caused by: java.io.IOException: Cannot run program "/opt/atlassian/pipelines/agent/build/alert-web/target/node/node" (in directory "/opt/atlassian/pipelines/agent/build/alert-web/src/main/resources/static/resources"): error=2, No such file or directory
...
Caused by: java.io.IOException: error=2, No such file or directory
...
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :alert-web
Skipping cache upload for failed step`

The structure of our project is:

project |______alert-business |_______pom.xml |______alert-util |_______pom.xml |______alert-web |_______pom.xml |______pom.xml

We have a react aplication with package.json inside one folder of alert-web subproject.

The aplication is compiling in local but not in the pipeline.

The pom.xml inside the alert-web subproject is:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>alert-web</artifactId>
    <packaging>war</packaging>
    <name>alert-web</name>
    <description>....</description>
    <parent>
        <groupId>es.company.alert</groupId>
        <artifactId>alert</artifactId>
        <version>1.0.0</version>
    </parent>
<properties>
    <aspectj.version>1.8.10</aspectj.version>
    <node.version>v10.9.0</node.version>
    <frontend-maven-plugin>1.9.1</frontend-maven-plugin>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
        <groupId>es.company.alert</groupId>
        <artifactId>alert-util</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>es.company.alert</groupId>
        <artifactId>alert-business</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.2</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.2</version>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<profiles>
    <profile>
        <id>local</id>
        <properties>
            <activatedProperties>local</activatedProperties>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>npm run build</id>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <phase>generate-resources</phase>
                            <configuration>
                                <arguments>run build:local --no-optional</arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>develop</id>
        <properties>
            <activatedProperties>develop</activatedProperties>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>npm run build</id>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <phase>generate-resources</phase>
                            <configuration>
                                <arguments>run build:dev --no-optional</arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>production</id>
        <properties>
            <activatedProperties>production</activatedProperties>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>npm run build</id>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <phase>generate-resources</phase>
                            <configuration>
                                <arguments>run build:production --no-optional</arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

</profiles>
<build>
    <!--
    <sourceDirectory>${project.build.directory}/generated-sources/delombok</sourceDirectory>
    -->
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <excludes>
                <exclude>**/node_modules/**</exclude>
                <exclude>**/react/**</exclude>
                <exclude>**/fonts/**</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
            <includes>
                <include>**/fonts/**</include>
            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <configuration>
                <nonFilteredFileExtensions>
                    <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
                    <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
                    <nonFilteredFileExtension>woff</nonFilteredFileExtension>
                    <nonFilteredFileExtension>svg</nonFilteredFileExtension>
                </nonFilteredFileExtensions>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <warName>alert</warName>
                <warSourceExcludes>node_modules/,react/</warSourceExcludes>
                <packagingExcludes>**/src/main/static/resources/node_modules/,**/src/main/static/resources/node/
                </packagingExcludes>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>1.9.1</version>
            <configuration>
                <nodeVersion>${node.version}</nodeVersion>
                <installDirectory>target</installDirectory>
                <workingDirectory>src/main/resources/static/resources</workingDirectory>
                <nodeDownloadRoot>https://nodejs.org/dist/</nodeDownloadRoot>
            </configuration>
            <executions>
                <execution>
                    <id>install node and npm</id>
                    <goals>
                        <goal>install-node-and-npm</goal>
                    </goals>
                    <phase>generate-resources</phase>
                </execution>
                <execution>
                    <id>npm install</id>
                    <goals>
                        <goal>npm</goal>
                    </goals>
                    <phase>generate-resources</phase>
                    <configuration>
                        <arguments>install --no-optional</arguments>
                        <installDirectory>target</installDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.9</version>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>default-report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <trimStackTrace>false</trimStackTrace>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>src/main/resources/static/resources/dist</directory>
                        <followSymlinks>false</followSymlinks>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>
    </plugins>
    <finalName>alert</finalName>
</build>

`

We try to solve the error installing npm in the pipeline but we can't not compile the project. We also try to use others docker images for the pipeline but we have the same error.

Can you help us?

Thanks.

trisquel87 avatar Jan 13 '20 16:01 trisquel87

Does it work when running locally?

eirslett avatar Jan 13 '20 16:01 eirslett

@eirslett yes, we don’t have any problem in local.

trisquel87 avatar Jan 13 '20 16:01 trisquel87

Try setting <installDirectory> and <workingDirectory> for every execution maybe?

eirslett avatar Jan 14 '20 11:01 eirslett

Try setting <installDirectory> and <workingDirectory> for every execution maybe?

@eirslett I have the same problem.

trisquel87 avatar Jan 20 '20 08:01 trisquel87

Is there any chance that the target directory is wiped out between executions, somehow? Or the node binary ends up in the wrong directory somehow? Try logging into the CI server/into the build pipeline and checking its filesystem?

eirslett avatar Jan 20 '20 14:01 eirslett

I had a issue running the plugin, but it was because plugin requires maven 3.1 and above.

KrKandula avatar Jan 29 '20 23:01 KrKandula

Normal npm/node releases won’t work on Alpine or any musl-libc based distribution. I had to abandon Alpine at work because this plugin is in many of our projects.

ghost avatar Mar 21 '20 03:03 ghost

Hello I'm having the same issue with gitlab ci @hermitmaster what are you using instead of Alpine?

hyahyaoui avatar May 20 '20 11:05 hyahyaoui

@hyahyaoui Debian slim based images. Really, anything with glibc works fine.

ghost avatar May 20 '20 11:05 ghost

@hermitmaster thanks :)

hyahyaoui avatar May 20 '20 11:05 hyahyaoui

frontend-maven-plugin downloads a musl-based NodeJS since https://github.com/eirslett/frontend-maven-plugin/pull/853, so there should no longer be a need to install glibc (which adds quite a bit of disk usage to that otherwise tiny Alpine image, and I guess keeping it small is the point of using Alpine).

breun avatar Apr 20 '21 08:04 breun