Error when executing Maven Command in Jenkins - java

I and running Jenkins in a Docker Container on my mac (locally) as per these instructions -
https://hackmamba.io/blog/2022/04/running-docker-in-a-jenkins-container/
I have installed my jdk
enter image description here
and set my Java Home here -
enter image description here
This is my simple pipelime
pipeline {
agent any
tools {
// Install the Maven version configured as "M3" and add it to the path.
maven '3.8.7'
}
stages {
stage('Example') {
steps {
sh 'echo ls '
sh 'echo $JAVA_HOME'
// Run Maven on a Unix agent.
sh 'mvn --version'
}
}
}
}
Every time I get this -
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.
I have no idea of how to find the path Jenkins installed the jdk too when it automatically installed it.
Please help
I've tried changing the path for JAVA_HOME - but I don't know what it would be in this environemnt

Which docker image this container made of? if it's official jeknins docker image - java comes installed already, and you do not need to install it. (as long as you are not adding nodes/agents).
However, if you need to install it, the installation should be in a local path in the container. you can give a specific location for the installation:
~/installed-here/
then the path should be ~/installed-here/jdk....
and JAVA_HOME should point to this path (a local linux/win path that in the container)

Related

When checking Maven in Jenkins I get this error "Could not open '/lib/ld-linux-aarch64.so.1': No such file or directory"

I've been looking at this for days.
I've created an instance of Jenkins in Docker to run locally using this DockerFile -
`FROM jenkins/jenkins:2.346.2-jdk11
USER root
RUN curl -sSL https://get.docker.com/ | sh
RUN usermod -a -G docker jenkins
USER jenkins
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN jenkins-plugin-cli --plugin-file /usr/share/jenkins/ref/plugins.txt
COPY seedJob.xml /usr/share/jenkins/ref/jobs/seed-job/config.xml
ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false`
I have then installed the JDK in Jenkins
I have then installed Maven in Jenkins
I have then created a simple Pipeline to test for Maven
`pipeline {
agent any
tools {
// Install the Maven version configured as "M3" and add it to the path.
maven '3.8.6'
jdk 'openjdk-171'
}
stages {
stage('Example') {
steps {
sh 'mvn --version'
}
}
}
}
`
AND I get this message
"Could not open '/lib/ld-linux-aarch64.so.1': No such file or directory"
I've tried rebuilding from Scratch, followed youtube tutorials - still nothing
(I'm also running on a Mac). Any help massively appreciated!
I expect it to return the version number of Maven
ld-linux-aarch64.so.1 is the dynamic linker for the guest binary. If you have a dynamically linked guest binary then you need to tell the emulator about not just the binary itself but also the dynamic linker and all the dynamic libraries that the guest binary links to (usually by passing it an option to tell it about a directory which has all the libraries in the usual places they would be on the real filesystem of the guest).
For gem5 you can use --redirects and --interp-dir

Jenkins Blue Ocean: Maven doesn't see Java

I'm getting the error "/var/jenkins_home/tools/hudson.model.JDK/jdk8/bin/java: not found:" even though the path exists:
[edi-debatcher_master-LNI22Y2C5V3VECCBCFPVB3ZUWJJNMLK6LIFEQ6V3OYH52T74NU3A#2] Running shell script
+ echo PATH = /var/jenkins_home/tools/hudson.model.JDK/jdk8/bin:/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3/bin:/var/jenkins_home/tools/hudson.model.JDK/jdk8/bin:/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin
PATH = /var/jenkins_home/tools/hudson.model.JDK/jdk8/bin:/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3/bin:/var/jenkins_home/tools/hudson.model.JDK/jdk8/bin:/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin
+ echo M2_HOME = /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3
M2_HOME = /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3
+ mvn -version
/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3/bin/mvn: exec: line 199: /var/jenkins_home/tools/hudson.model.JDK/jdk8/bin/java: not found
I am using the Jenkins Blue Ocean feature, GitHub Jenkinsfile. I have "jdk8" and "Maven 3.5.3" defined in Global Tool Configuration, "autoinstall" checked.
Here is my Jenkinsfile:
pipeline {
agent any
stages {
stage('Initialize') {
steps {
sh '''
echo "PATH = ${PATH}"
echo "M2_HOME = ${M2_HOME}"
mvn --version
'''
}
}
stage('Build') {
steps {
sh 'mvn -Dmaven.test.failure.ignore=true install'
}
post {
success {
junit 'target/surefire-reports/**/*.xml'
}
}
}
}
tools {
maven 'Maven 3.5.3'
jdk 'jdk8'
}
post {
always {
deleteDir()
}
}
}
You are running a wrong version of the file (here java) for the system.
Problem:
The file is there and can not be executed. The error message is "No such file or directory"
Solution:
You are running the wrong file version for your system.
The problem can occur for example if you run your Jenkins installation in a Docker container with Alpine Linux, since Alpine uses musl libc. The Oracle Java binaries only run on glibc.
The problem was that the Oracle JDK autoinstall didn't really do anything on my system (confirmed by checking Jenkins' system properties for Java). I found that openjdk 1.8 happen to already be on that container, so I manually pointed JAVA_HOME to that instead of relying on the Oracle JDK autoinstall.
Once I changed the project JDK setting to system, my build progressed past this error.

Can't set up Maven on Mac OSX

I am new to Mac OSX and I'm running Yosemite. I am trying to set up Maven using this official guide in order to set up a Google Cloud Messaging Backend. Here's what I did:
1) Downloaded Maven zip (version: apache-maven-3.3.9) and Unzipped it
2) As the guide says, I need to add the bin directory to my PATH variable. So I did the following in my terminal
export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.9
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60
export PATH=$JAVA_HOME/bin:$M2_HOME/bin:$PATH
The terminal didn't return any response. However when I checked to see if Maven got installed using:
mvn -version
I get a message saying:
-bash: mvn: command not found
What am I doing wrong? Did I follow the steps properly to set up Maven?
EDIT:
MVN Bin Directory path is:
/Users/Earthling/Documents/Projects/MobiProject/apache-maven-3.3.9
I tried all the manual steps here and still couldn't get it to work. Then I realized I can easily install it using Homebrew, much more convenient:
brew install maven
that's all you need to install maven for mac!
The $PATH is what point where your programs are, because of that you change it in order to find mvn. Actually you are pointing $PATH to $M2_HOME/bin.
You need to update $M2_HOME to one directory level before mvn bin and before update $PATH.
If this is your mvn home:
/Users/Earthling/Documents/Projects/MobiProject/apache-maven-3.3.9
you should use this env vars:
export M2_HOME="/Users/Earthling/Documents/Projects/MobiProject/apache-maven-3.3.9"
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_60"
export PATH="$JAVA_HOME/bin:$M2_HOME/bin:$PATH"
You can also edit your ~/.profile in order to include these lines, so you don't need to type these exports whenever you open your terminal.
Do
export M2_HOME=/Users/Earthling/Documents/Projects/MobiProject/apache-maven-3.3.9

Apache Maven installation in window 8

Actually I tried to install Apache Maven to my system.
I followed these steps:
Downloaded apache-maven-3.3.3 in my Window 8 machine and copied to Program Files.
Then added maven path C:\Program Files\apache-maven-3.3.3 as M2_HOME in system variable and added C:\Program Files\Java\jdk1.8.0_31 as JAVA_HOME.
Then added ;%M2_HOME%\bin to default Path.
Then tried to run as mvn -version in CMD.
But I got the result like:
mvn is not recognized as an internal or external command...
I remember I had similar issue some time ago on Windows 7. On Windows 8 it may behave similarly. Your solution should work correctly, but for some reason it's not working.
Add path to bin/ directory inside your Maven directory to the Path system variable after semicolon. In your case it will be:
C:\Program Files\apache-maven-3.3.3\bin
Save Path variable, close terminal, run it again and type: mvn -version.

Run Maven, Gradle or other batch-based script from Java (and then Eclipse)

I am making Eclipse plugin that run alternative build from within Eclipse
(e.g. for project that have both pom.xml and build.gradle do run with mvn package or gradle build)
But entry point for both of them are batch .bat files on Windows and bash on Linux.
For Windows running from Java would look like
Runtime.getRuntime().exec("cmd /c start mvn");
but that will start new window, while I want it to see running in Eclipse Console.
There must be something like but in Eclipse way I guess. How to run such script from Eclipse and see output in Console?
This is meant to be alternative and not dependent on m2e and Gradle Integration.
Did just as for Node.js using full path to maven installation (that should be selected in Preferences). But it is weird that I needed to pass JAVA_HOME and M2_HOME, because otherwise I get JAVA_HOME not found or M2_HOME not found, just like when maven is not yet set up:
ERROR: M2_HOME not found in your environment.
Please set the M2_HOME variable in your environment to match the
location of the Maven installation
related code
public class LaunchConfigurationDelegate implements ILaunchConfigurationDelegate {
#Override
public void launch(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException {
// skipped some argument processing
envp[idx++] = "JAVA_HOME=" + System.getProperty("java.home");
envp[idx++] = "M2_HOME=" + System.getenv("MAVEN_HOME");
String[] cmds = {};
cmds = cmdLine.toArray(cmds);
// Launch a process to run/debug. See also #71 (output is less or no output)
Process p = DebugPlugin.exec(cmds, workingPath, envp);
// no way to get private p.handle from java.lang.ProcessImpl
RuntimeProcess process = (RuntimeProcess)DebugPlugin.newProcess(launch, p, Constants.PROCESS_MESSAGE);
Is there some more beautiful way to do that? Please add as an answer.
UPDATE: This does not fully solves the problem, see Java - process launched with Runtime.getRuntime().exec( cannot create temp file

Categories