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

JAVA_HOME from pipeline not respected in artifactory maven run

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • artifactory-plugin
    • None
    • build agent: centos 7.2
      default JDK: 1.7

      The maven.run uses the system default JAVA instead of the JAVA_HOME configured in the pipeline.

      env.JAVA_HOME = tool name: 'JAVA8', type: 'jdk'
      env.PATH = "${env.JAVA_HOME}/bin:${env.PATH}"
      
      def rtMaven = Artifactory.newMavenBuild()
      rtMaven.tool = 'mvn'
      rtMaven.run pom: 'pom.xml', goals: ' -Dmaven.repo.local=.repository install javadoc:jar source:jar'
      

      The build fails with error:

      Fatal error compiling: invalid target release: 1.8 as the java command used is the system default 1.7

          [JENKINS-40282] JAVA_HOME from pipeline not respected in artifactory maven run

          This issue has been fixed in version 2.8.2 of the Artifactory Plugin, which was released two days ago:
          https://www.jfrog.com/jira/browse/HAP-848
          All you need configure in your Pipeline script is:
          env.JAVA_HOME = 'your JAVA_HOME path'
          We will soon document this as part of the Artifactory Pipeline DSL documentation:
          https://wiki.jenkins-ci.org/display/JENKINS/Artifactory+-+Working+With+the+Pipeline+Jenkins+Plugin

          Eyal Ben Moshe added a comment - This issue has been fixed in version 2.8.2 of the Artifactory Plugin, which was released two days ago: https://www.jfrog.com/jira/browse/HAP-848 All you need configure in your Pipeline script is: env.JAVA_HOME = 'your JAVA_HOME path' We will soon document this as part of the Artifactory Pipeline DSL documentation: https://wiki.jenkins-ci.org/display/JENKINS/Artifactory+-+Working+With+the+Pipeline+Jenkins+Plugin

          Justin Patrin added a comment -

          Are we required to set the global environment to make this work? Can we use withEnv() instead?

          Justin Patrin added a comment - Are we required to set the global environment to make this work? Can we use withEnv() instead?

          Hi Justin,
          Both withEnv() and env.JAVA_HOME should work.

          Eyal Ben Moshe added a comment - Hi Justin, Both withEnv() and env.JAVA_HOME should work.

            eyalbe Eyal Ben Moshe
            marcrobinson Marc Robinson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: