Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-33966

JAVA_HOME is not set when Maven is automatically installed

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Not A Defect
    • Component/s: pipeline
    • Labels:
    • Environment:
      Windows 10, Jenkins 2.0-beta-1, JDK 1.8.0_77
    • Similar Issues:

      Description

      I run Jenkins 2.0 beta binary under Windows 10.
      I declared a Maven installation "M3" under Global Tool Configuration.
      I created the pipeline job with the following script:

      node {
        git url: 'https://github.com/jglick/simple-maven-project-with-tests.git'
        def mvnHome = tool 'M3'
        bat "${mvnHome}\\bin\\mvn -B verify"
      }
      

      I get the following error when installing Maven:

      Started by user Administrateur
      [Pipeline] Allocate node : Start
      Running on master in C:\Program Files (x86)\Jenkins\workspace\myPipeline
      [Pipeline] node {
      [Pipeline] git
      Cloning the remote Git repository
      remote: Counting objects
      Receiving objects
      Resolving deltas
      Updating references
      Checking out Revision 7dac409d4bd2fec35a4ccde0cb424042cba671df (refs/remotes/origin/master)
      First time build. Skipping changelog.
      [Pipeline] tool
      Unpacking http://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip to C:\Program Files (x86)\Jenkins\tools\hudson.tasks.Maven_MavenInstallation\M3 on Jenkins
      [Pipeline] bat
      [myPipeline] Running batch script
      
      C:\Program Files (x86)\Jenkins\workspace\myPipeline>"C:\Program Files (x86)\Jenkins\tools\hudson.tasks.Maven_MavenInstallation\M3"\bin\mvn -B verify 
      
      Error: JAVA_HOME not found in your environment. 
      Please set the JAVA_HOME variable in your environment to match the 
      location of your Java installation. 
      
      [Pipeline] } //node
      [Pipeline] Allocate node : End
      [Pipeline] End of Pipeline
      ERROR: script returned exit code 1
      Finished: FAILURE
      

      Workaround: I have to declare explicitely JAVA_HOME environment variable in Manage Jenkins -> Configure System -> Global properties section. I set it to "C:\Program Files\Java\jdk1.8.0_77"
      After that the build works correctly

      Clearly I think on Global Tool Configuration, a Maven installation should be bind to a JDK installation to avoid such issue. Concretely in Maven widget a combobox should be present to select a JDK installation already configured above.

        Attachments

          Issue Links

            Activity

            lautou Laurent TOURREAU created issue -
            abayer Andrew Bayer made changes -
            Field Original Value New Value
            Priority Minor [ 4 ] Critical [ 2 ]
            Hide
            danielbeck Daniel Beck added a comment -

            Why not have Jenkins also install Java?

            Is Java on your PATH?

            Show
            danielbeck Daniel Beck added a comment - Why not have Jenkins also install Java? Is Java on your PATH?
            Hide
            danielbeck Daniel Beck added a comment -

            Straightforward workaround present, therefore reducing priority.

            Also, could probably define JDK installations (with a defined path, doesn't need to be auto-installed), and reference those in the pipeline.

            Show
            danielbeck Daniel Beck added a comment - Straightforward workaround present, therefore reducing priority. Also, could probably define JDK installations (with a defined path, doesn't need to be auto-installed), and reference those in the pipeline.
            danielbeck Daniel Beck made changes -
            Priority Critical [ 2 ] Minor [ 4 ]
            Hide
            lautou Laurent TOURREAU added a comment - - edited

            On Global Tool Configuration, I add a new JDK installation called "JDK-1.8".
            I set the JAVA_HOME field under installation name to C:\Program Files\Java\jdk1.8.0_77 and run the job again -> same result JAVA_HOME is not found.

            Show
            lautou Laurent TOURREAU added a comment - - edited On Global Tool Configuration, I add a new JDK installation called "JDK-1.8". I set the JAVA_HOME field under installation name to C:\Program Files\Java\jdk1.8.0_77 and run the job again -> same result JAVA_HOME is not found.
            Hide
            danielbeck Daniel Beck added a comment -

            What happens when you call tool 'JDK-1.8' in your pipeline?

            Show
            danielbeck Daniel Beck added a comment - What happens when you call tool 'JDK-1.8' in your pipeline?
            Hide
            lautou Laurent TOURREAU added a comment - - edited

            I did this as it :

            node {
              git url: 'https://github.com/jglick/simple-maven-project-with-tests.git'
              def mvnHome = tool 'M3'
              tool 'JDK-1.8'
              bat "\"${mvnHome}\"\\bin\\mvn -B verify"
            }
            

            I still get the error:

            [Pipeline] Allocate node : Start
            Running on master in C:\Program Files (x86)\Jenkins\workspace\myPipeline
            [Pipeline] node {
            [Pipeline] git
            Fetching changes from the remote Git repository
            Checking out Revision 7dac409d4bd2fec35a4ccde0cb424042cba671df (refs/remotes/origin/master)
            [Pipeline] tool
            [Pipeline] tool
            [Pipeline] bat
            [myPipeline] Running batch script
            
            C:\Program Files (x86)\Jenkins\workspace\myPipeline>"C:\Program Files (x86)\Jenkins\tools\hudson.tasks.Maven_MavenInstallation\M3"\bin\mvn -B verify 
            
            Error: JAVA_HOME not found in your environment. 
            Please set the JAVA_HOME variable in your environment to match the 
            location of your Java installation. 
            
            [Pipeline] } //node
            [Pipeline] Allocate node : End
            [Pipeline] End of Pipeline
            ERROR: script returned exit code 1
            Finished: FAILURE
            

            If i explicitely set JAVA_HOME, it works

            node {
              git url: 'https://github.com/jglick/simple-maven-project-with-tests.git'
              def mvnHome = tool 'M3'
              env.JAVA_HOME = tool 'JDK-1.8'
              bat "\"${mvnHome}\"\\bin\\mvn -B verify"
            }
            
            Show
            lautou Laurent TOURREAU added a comment - - edited I did this as it : node { git url: 'https: //github.com/jglick/simple-maven-project-with-tests.git' def mvnHome = tool 'M3' tool 'JDK-1.8' bat "\" ${mvnHome}\ "\\bin\\mvn -B verify" } I still get the error: [Pipeline] Allocate node : Start Running on master in C:\Program Files (x86)\Jenkins\workspace\myPipeline [Pipeline] node { [Pipeline] git Fetching changes from the remote Git repository Checking out Revision 7dac409d4bd2fec35a4ccde0cb424042cba671df (refs/remotes/origin/master) [Pipeline] tool [Pipeline] tool [Pipeline] bat [myPipeline] Running batch script C:\Program Files (x86)\Jenkins\workspace\myPipeline> "C:\Program Files (x86)\Jenkins\tools\hudson.tasks.Maven_MavenInstallation\M3" \bin\mvn -B verify Error: JAVA_HOME not found in your environment. Please set the JAVA_HOME variable in your environment to match the location of your Java installation. [Pipeline] } //node [Pipeline] Allocate node : End [Pipeline] End of Pipeline ERROR: script returned exit code 1 Finished: FAILURE If i explicitely set JAVA_HOME, it works node { git url: 'https: //github.com/jglick/simple-maven-project-with-tests.git' def mvnHome = tool 'M3' env.JAVA_HOME = tool 'JDK-1.8' bat "\" ${mvnHome}\ "\\bin\\mvn -B verify" }
            Hide
            danielbeck Daniel Beck added a comment -

            Not sure that's how it's supposed to work. Jesse Glick?

            Show
            danielbeck Daniel Beck added a comment - Not sure that's how it's supposed to work. Jesse Glick ?
            Hide
            jglick Jesse Glick added a comment -

            See discussion in JENKINS-34012.

            Show
            jglick Jesse Glick added a comment - See discussion in JENKINS-34012 .
            jglick Jesse Glick made changes -
            Link This issue is related to JENKINS-28718 [ JENKINS-28718 ]
            jglick Jesse Glick made changes -
            Link This issue is related to JENKINS-34012 [ JENKINS-34012 ]
            jglick Jesse Glick made changes -
            Resolution Not A Defect [ 7 ]
            Status Open [ 1 ] Resolved [ 5 ]
            jglick Jesse Glick made changes -
            Component/s workflow-plugin [ 18820 ]
            Component/s core [ 15593 ]
            lautou Laurent TOURREAU made changes -
            Link This issue is related to JENKINS-34012 [ JENKINS-34012 ]
            Hide
            lautou Laurent TOURREAU added a comment -

            To be clearer in this ticket, I quote your comment in JENKINS-34012:
            "The tool step merely ensures that the tool is present. Its return value is the path. If you want to set environment variables, that is up to you. JENKINS-28718 would help automate it."

            Show
            lautou Laurent TOURREAU added a comment - To be clearer in this ticket, I quote your comment in JENKINS-34012 : " The tool step merely ensures that the tool is present. Its return value is the path. If you want to set environment variables, that is up to you. JENKINS-28718 would help automate it. "
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 169977 ] JNJira + In-Review [ 198753 ]
            abayer Andrew Bayer made changes -
            Component/s pipeline-general [ 21692 ]
            abayer Andrew Bayer made changes -
            Component/s workflow-plugin [ 18820 ]

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              lautou Laurent TOURREAU
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: