1
votes

jenkinspipeline is unable to build the springboot application

`+ mvn -f EquipOptimizationApi/AddNewEquipment/pom.xml install
    ----- withMaven Wrapper script -----
    Picked up JAVA_TOOL_OPTIONS: -Dmaven.ext.class.path="/var/lib/jenkins/workspace/addNewEquip@tmp/withMaven2d5b8b4d/pipeline-maven-spy.jar"

-Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder="/var/lib/jenkins/workspace/addNewEquip@tmp/withMaven2d5b8b4d"

    Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T18:33:14Z)
    Maven home: /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven
    Java version: 1.8.0_171, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.amzn2.x86_64/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: "linux", version: "4.14.47-64.38.amzn2.x86_64", arch: "amd64", family: "unix"
    [INFO] [jenkins-event-spy] Generate /var/lib/jenkins/workspace/addNewEquip@tmp/withMaven2d5b8b4d/maven-spy-20180718-135754-559519187898694815320.log.tmp

... [INFO] Scanning for projects... [INFO] [INFO] ----------------------< com.miss:AddNewEquipment >---------------------- [INFO] Building AddNewEquipment 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ AddNewEquipment --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] Copying 5 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ AddNewEquipment --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 13 source files to /var/lib/jenkins/workspace/addNewEquip/EquipOptimizationApi/AddNewEquipment/target/classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [INFO] 1 error [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.893 s [INFO] Finished at: 2018-07-18T13:57:57Z [INFO] ------------------------------------------------------------------------ [INFO] [jenkins-event-spy] Generated /var/lib/jenkins/workspace/addNewEquip@tmp/withMaven2d5b8b4d/maven-spy-20180718-135754-559519187898694815320.log [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project AddNewEquipment: Compilation failure [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [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/MojoFailureException [Pipeline] } [withMaven] Jenkins Task Scanner Plugin not found, don't display results of source code scanning for 'TODO' and 'FIXME' in pipeline screen. [Pipeline] // withMaven [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: script returned exit code 1 Finished: FAILURE`

1
There is clear information No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?3sky
But same code works in same jenkins server without pipeline i mean normal jobMaharudrappa A

1 Answers

0
votes

In your pipeline, you have to declare the jdk.

You have to configure tool jdk in global tools administration.

Example:

pipeline {
    tools {
        jdk 'openjdk-1.8'
        maven 'Maven_3_5_2'
    }
    stages {
        stage('Build') {
            steps {
                echo 'Building..'
                sh "mvn clean install"
            } 
        }
    }
}

You can also modify JAVA_HOME localy to the node.

node {
  jdk = tool name: 'JDK17'
  env.JAVA_HOME = "${jdk}"

  echo "jdk installation path is: ${jdk}"

  // next 2 are equivalents
  sh "${jdk}/bin/java -version"

  // note that simple quote strings are not evaluated by Groovy
  // substitution is done by shell script using environment
  sh '$JAVA_HOME/bin/java -version'
}

src: https://support.cloudbees.com/hc/en-us/articles/115001595227-How-To-Specify-A-Specific-JDK-In-Pipeline-