Thursday, February 17, 2022

[SOLVED] failed to run maven commands on remote Centos 7 server

Issue

Jenkins is able to fetch the repo inside /var/lib/jenkins/workspace/demo_2 but maven is failing to run mvn clean verify -Dwebdriver.driver=chrome and give following error.

Started by user Aditi
Building on master in workspace /var/lib/jenkins/workspace/demo_2
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Done
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent]   Exec ssh-agent (binary ssh-agent on a remote machine)
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-xGCSGsv8AXIe/agent.18464
SSH_AGENT_PID=18467
[ssh-agent] Started.
Running ssh-add (command line suppressed)
Identity added: /var/lib/jenkins/workspace/demo_2@tmp/private_key_6332013581283531930.key (/var/lib/jenkins/workspace/demo_2@tmp/private_key_6332013581283531930.key)
[ssh-agent] Using credentials Aditi
Cloning the remote Git repository
Cloning repository https://[email protected]/storetech/riverbed.git
 > git init /var/lib/jenkins/workspace/demo_2 # timeout=10
Fetching upstream changes from https://[email protected]/storetech/riverbed.git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials aditi's bitbucket credentials
 > git fetch --tags --progress https://[email protected]/storetech/riverbed.git +refs/heads/*:refs/remotes/origin/*
 > git config remote.origin.url https://[email protected]/storetech/riverbed.git # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url https://[email protected]/storetech/riverbed.git # timeout=10
Fetching upstream changes from https://[email protected]/storetech/riverbed.git
using GIT_ASKPASS to set credentials aditi's bitbucket credentials
 > git fetch --tags --progress https://[email protected]/storetech/riverbed.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse origin/pemissionsTests^{commit} # timeout=10
Checking out Revision 46dd6e8872bfa4f89fc8b988279f4ac336521e18 (origin/pemissionsTests)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 46dd6e8872bfa4f89fc8b988279f4ac336521e18
Commit message: "permission test initial commit"
 > git rev-list --no-walk 46dd6e8872bfa4f89fc8b988279f4ac336521e18 # timeout=10
[demo_2] $ mvn clean verify -Dwebdriver.driver=chrome
FATAL: command execution failed
java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
Caused: java.io.IOException: Cannot run program "mvn" (in directory "/var/lib/jenkins/workspace/demo_2"): error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at hudson.Proc$LocalProc.<init>(Proc.java:249)
    at hudson.Proc$LocalProc.<init>(Proc.java:218)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:935)
    at hudson.Launcher$ProcStarter.start(Launcher.java:454)
    at hudson.Launcher$ProcStarter.join(Launcher.java:465)
    at hudson.tasks.Maven.perform(Maven.java:368)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
    at hudson.model.Build$BuildExecution.build(Build.java:206)
    at hudson.model.Build$BuildExecution.doRun(Build.java:163)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
    at hudson.model.Run.execute(Run.java:1815)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Build step 'Invoke top-level Maven targets' marked build as failure
$ ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 18467 killed;
[ssh-agent] Stopped.
Finished: FAILURE

If I login via putty to this Centos 7 server, go to demo_2 location and run mvn clean verify -Dwebdriver.driver=chrome -e with -e switch it gives me below error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:testResources (default-testResources) on project demo-automation-tests: Cannot create resource output directory: /var/lib/jenkins/workspace/demo_2/target/test-classes -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:testResources (default-testResources) on project demo-automation-tests: Cannot create resource output directory: /var/lib/jenkins/workspace/demo_2/target/test-classes
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:954)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Cannot create resource output directory: /var/lib/jenkins/workspace/demo_2/target/test-classes
    at org.apache.maven.plugin.resources.ResourcesMojo.execute (ResourcesMojo.java:307)
    at org.apache.maven.plugin.resources.TestResourcesMojo.execute (TestResourcesMojo.java:73)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:954)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.shared.filtering.MavenFilteringException: Cannot create resource output directory: /var/lib/jenkins/workspace/demo_2/target/test-classes
    at org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering.filterResources (DefaultMavenResourcesFiltering.java:215)
    at org.apache.maven.plugin.resources.ResourcesMojo.execute (ResourcesMojo.java:301)
    at org.apache.maven.plugin.resources.TestResourcesMojo.execute (TestResourcesMojo.java:73)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:954)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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/MojoExecutionException

I guess maven doesnt have rights to create directory, but it is the same user credentials I am using on Jenkins and using to login via putty

How come git works?

What am I missing, here? This un-abilty of maven to create directory is happening only inside /var/lib/jenkins it works fine inside

/home/aditi.a/workspace, if I copy same workspace.

.profile file

export M3_HOME=/home/aditi.a/apache-maven-3.5.4/bin
export PATH=$PATH:$M3_HOME

export JMETER_HOME=/home/aditi.a/apache-jmeter-5.0/bin
export PATH=$PATH:$JMETER_HOME

export JAVA_HOME=/usr/java/jdk1.8.0_192-amd64
export PATH=$PATH:$HOME/bin:$JAVA_HOME/bin

export DISPLAY=:99

Solution

Try mvn in same directory where you are trying to run tests and its failing.

If it says mvn command not found then maven that you installed and have in your .profile file is good for your home/user only i.e. home/aditi.a only

Try copying contents from .profile file to these locations also

  1. /home/aditi.a/.bashrc,
  2. /root/.profile and
  3. /root/.bashrc


Answered By - paul
Answer Checked By - Marie Seifert (WPSolving Admin)