Monday, July 24, 2017

Jenkins slave node gives error /bin/java": java.io.IOException: error=2 when trying to build project

/bin/java": java.io.IOException: error=2
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.(UNIXProcess.java:164)
    at java.lang.ProcessImpl.start(ProcessImpl.java:81)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:476)


As the error indicates the you need to check the environment variables 'JAVA_HOME' or 'java.home' on the slave node. You need to make sure that 'JAVA_HOME' or 'java.home' is pointing to say in linux /opt/common/vendor/jdk1.7.0_79 and not /opt/common/vendor/jdk1.7.0_79/jre.

To check the configuration you can login to Jenkins as admin and then
select Manage Hudson/Jenkins then choose Manage Nodes.
there should be a Node Properties section.
Check the Tool Locations checkbox.
Click on Add/Update then Select your JDK in the dropdown list and add the path to it.

sonar-maven-plugin Insufficient privileges

When using "sonar-maven-plugin" as part of the jenkins build process, you might encounter this error message "[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar (default-cli) on project service1-data: Insufficient privileges -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar (default-cli) on project service1-data: Insufficient privileges
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
".

To fix this issue make sure that jenkins continuous integration (CI) job is building with correct projects' pom.xml in multi-module project. For example if your project has the following hierarchy
project/pom.xml
project/folder1/pom.xml
project/folder2/pom.xml

then if jenkins CI build is using project/pom.xml then
the sonar jenkins job (using sonar-maven-plugin) should also be using project/pom.xml

If the jenkins CI job is using project/pom.xml but sonar jenkins job is using different pom.xml say project/folder1/pom.xml then you will get above error.