jenkins-docs/simple-java-maven-app

Deliver Stage build failed on Jenkins

brianpenrose opened this issue · 2 comments

Get this following error when trying to run the maven app on Jenkins.

+ ./jenkins/scripts/deliver.sh
The following Maven command installs your Maven-built Java application
into the local Maven repository, which will ultimately be stored in
Jenkinss local Maven repository (and the "maven-repository" Docker data
volume).
+ mvn jar:jar install:install help:evaluate -Dexpression=project.name
[�[1;34mINFO�[m] Scanning for projects...
[�[1;34mINFO�[m] 
[�[1;34mINFO�[m] �[1m----------------------< �[0;36mcom.mycompany.app:my-app�[0;1m >----------------------�[m
[�[1;34mINFO�[m] �[1mBuilding my-app 1.0-SNAPSHOT�[m
[�[1;34mINFO�[m] �[1m--------------------------------[ jar ]---------------------------------�[m
[�[1;34mINFO�[m] 
[�[1;34mINFO�[m] �[1m--- �[0;32mmaven-jar-plugin:3.3.0:jar�[m �[1m(default-cli)�[m @ �[36mmy-app�[0;1m ---�[m
[�[1;34mINFO�[m] 
[�[1;34mINFO�[m] �[1m--- �[0;32mmaven-install-plugin:2.4:install�[m �[1m(default-cli)�[m @ �[36mmy-app�[0;1m ---�[m
[�[1;34mINFO�[m] Installing /var/jenkins_home/workspace/GitHub Pipeline/target/my-app-1.0-SNAPSHOT.jar to /var/jenkins_home/.m2/repository/com/mycompany/app/my-app/1.0-SNAPSHOT/my-app-1.0-SNAPSHOT.jar
[�[1;34mINFO�[m] Installing /var/jenkins_home/workspace/GitHub Pipeline/pom.xml to /var/jenkins_home/.m2/repository/com/mycompany/app/my-app/1.0-SNAPSHOT/my-app-1.0-SNAPSHOT.pom
[�[1;34mINFO�[m] 
[�[1;34mINFO�[m] �[1m----------------------< �[0;36mcom.mycompany.app:my-app�[0;1m >----------------------�[m
[�[1;34mINFO�[m] �[1mBuilding my-app 1.0-SNAPSHOT�[m
[�[1;34mINFO�[m] �[1m--------------------------------[ jar ]---------------------------------�[m
[�[1;34mINFO�[m] 
[�[1;34mINFO�[m] �[1m--- �[0;32mmaven-help-plugin:3.4.0:evaluate�[m �[1m(default-cli)�[m @ �[36mmy-app�[0;1m ---�[m
[�[1;34mINFO�[m] No artifact parameter specified, using 'com.mycompany.app:my-app:jar:1.0-SNAPSHOT' as project.
[�[1;34mINFO�[m] 
my-app
[�[1;34mINFO�[m] �[1m------------------------------------------------------------------------�[m
[�[1;34mINFO�[m] �[1;32mBUILD SUCCESS�[m
[�[1;34mINFO�[m] �[1m------------------------------------------------------------------------�[m
[�[1;34mINFO�[m] Total time:  0.732 s
[�[1;34mINFO�[m] Finished at: 2024-04-09T16:53:28Z
[�[1;34mINFO�[m] �[1m------------------------------------------------------------------------�[m
�[0m�[0m+ set +x
The following command extracts the value of the <name/> element
within <project/> of your Java/Maven projects "pom.xml" file.
++ mvn -q -DforceStdout help:evaluate -Dexpression=project.name
�[0m+ NAME='my-app�[0m'
+ set +x
The following command behaves similarly to the previous one but
extracts the value of the <version/> element within <project/> instead.
++ mvn -q -DforceStdout help:evaluate -Dexpression=project.version
�[0m+ VERSION='1.0-SNAPSHOT�[0m'
+ set +x
The following command runs and outputs the execution of your Java
application (which Jenkins built using Maven) to the Jenkins UI.
+ java -jar 'target/my-app�[0m-1.0-SNAPSHOT�[0m.jar'
Error: Unable to access jarfile target/my-app�[0m-1.0-SNAPSHOT�[0m.jar
image

I just faced the same issue today, and found the reason after digging for an hour.
Maven outputs color codes for terminal, so the NAME and VERSION variable will contain escape sequences that are not visible in terminal, but picked up by commands when you use them in file names.

I tried using -B and -Dstyle.color=never params to mvn command, but they didn't work. It apparently is outputting the color codes anyway.

I ended up adding sed to the output to strip them away:

NAME=`mvn -q -DforceStdout help:evaluate -Dexpression=project.name | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g'`
VERSION=`mvn -q -DforceStdout help:evaluate -Dexpression=project.version | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g'`

Thanks, that solved it!