Error happened while attempting to execute 'mvn clean package' in Go CD - maven

I have setup a pipeline with one task mvn clean package in Go CD. I have registered an agent with Java and Maven up and running. When I trigger the pipeline, the job fails:
[go] Task: mvn clean package took: 0.14s
Error happened while attempting to execute 'mvn clean package'.
Please make sure [mvn] can be executed on this agent.
[Debug Information] Environment variable PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-11-openjdk/bin
I have tried all solutions provided on the below post-but nothing works
Can't execute "mvn clean package" task in GO CD

I encountered the same problem,
If i execute
docker exec -it gocd-agent bash
and execute mvn --version,will not tip me error
but if i execute
docker exec -it gocd-agent sh,will tip me "mvn: command not found"
so i feel the problem is bash and sh 'difference.

Try this.
Run whereis mvn on your agent then copy the path where mvn is installed and use it as the command in GoCD.
For me it was like this:
Command
/opt/apache-maven-3.8.2/bin/mvn
Arguments
clean
package

Related

Multiple maven install commands in Linux

I am running an azure pipeline for a maven project which has windows commands for maven installation, by calling multiple methods i.e.,
call mvn ... clean install
call mvn ... clean package (authentication)
call mvn ... clean package (restapi)
The build environment is linux Hence I am converting all the commands in the batch file to sh commands. For maven installation I initially added a maven installation task by mentioning the path and commands in the task. This failed.
So I am currently changing the windows commands to sh commands. The other commands except for maven installation have been converted using a batch to sh commands reference article.
Could some one guide me to convert the above mentioned installation commands to sh commands?
If the Apache Maven has been installed and added to the system path on the agent machine where your pipeline runs, you can just try directly calling the mvn command in the bash script, like you call it on Windows.
For example:
mvn ... clean install
mvn ... clean package (authentication)
mvn ... clean package (restapi)
Before you execute the bash script in the pipeline, you firstly should try and debug it on your local machine to make sure it can work as expected on the local machine. Then move the bash script to the pipeline on Azure DevOps.
If the bash script runs failed in the pipeline, for us to investigate this issue further, please share us with the complete debug logs of the failed pipeline run. To get the debug logs, you need to set the pipeline variable System.Debug to true, then trigger the pipeline.

Jhipster project runs fine on Mac, but fails to run on Linux

I have a JHipster project that includes Spring Boot and React Native. I run it OK using ./mvnw as the guide specifies, however, when I put the entire project on Ubuntu, it fails to run and the log is as follows:
ERROR Failed to execute goal
com.github.eirslett:frontend-maven-plugin:1.8.0:npm (webpack build dev)
on project galley-1: Failed to run task: 'npm run webpack:build' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.8.0:npm (webpack build dev)
Some points to note are that: I use sudo, and I already changed the webpack space size to be as big as 9000, in package.json.
Just to answer my own question, I finally find a way to run this:
On mac, I package my project using 'mvn -Pprod package -DskipTests' (sorry there were some tests that didn't pass at that time, I didn't get time to fix those at that time), and then on Linux:
nohup sudo java -jar *.jar &
It will do the trick. But if anyone gets any better idea, please share.

Maven wrapper in jenkins

I'm trying to test build a maven based project in jenkins.
https://github.com/tonsV2/Lift-Log-Backend
However I get the following error.
[Lift Log Backend] $ /bin/sh -xe /tmp/hudson4180120395829748105.sh
+ ./mvnw clean
Error: Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Any clues?
Seems like you have spaces in your Jenkins job name. Try to rename your job from "Lift Log Backend" to "Lift-Log-Backend"
I had the same issue, after renaming the Jenkins job, the error was gone.

Can't execute "mvn clean package" task in GO CD

I have setup a "Hello World" pipeline with one task mvn clean package in Go CD. I have registered an agent with Java and Maven up and running.
When I trigger the pipeline, the job fails:
12:05:08.655 [go] Start to execute task: <exec command="mvn" > <arg>clean package</arg> </exec>.
12:05:08.660 Error happened while attempting to execute 'mvn clean package'. Please make sure [mvn] can be executed on this agent.
If I execute mvn clean package in my agent, everything works. What is happening? Is there a place where I can see more specific logs?
Instead of running the following:
Command:
mvn clean package
try to use
Command:
/bin/bash
Arguments:
-c
mvn clean package
I struggled with the same issue and figured out a solution which worked for me. Maybe, it will help you.
In the command prompt of your agent enter echo $PATH
This will show all your path variables. Copy all of them.
Now, in the GUI of your server, choose the configuration of your
pipeline and add a PATH variable with the copied variables.
You can use:
Command:
mvn
Arguments:
clean
package

Executing maven compile commands from bash sequentially

I'm trying to build a project with Maven sequentially, with no success.
I tried put the following lines in a script file and called it from bash.
mvn -f ./cmroad-api/pom.xml clean install corona:package -Ddebug=false
mvn -f ./cmroad-impl/pom.xml clean install corona:package -Ddebug=false
The first command runs but the build does not call the second command. I tried putting the ; like:
mvn -f ./cmroad-api/pom.xml clean install corona:package -Ddebug=false; mvn -f ./cmroad-impl/pom.xml clean install corona:package -Ddebug=false.
The output was:
[ERROR] Unknown lifecycle phase "mvn". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>.
I would be most thankful for any help.
[ERROR] Unknown lifecycle phase "mvn".
This is the error you would get on typing mvn mvn; your script has two mvns on the same line, presumably because something is wrong with your line endings.
Start with a simple script:
#!/bin/sh
echo A
echo B
and get that working before moving on to Maven. The commands you specify should work when placed in a correctly prepared script. (Although, as khmarbaise says, your project is wrong if you need to build in this order.)

Resources