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

Environment variables not passed through to Ant tasks

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • ant-plugin
    • None
    • Platform: All, OS: All

      It appears that environment variables available in the Hudson configuration
      (i.e. visible in the Hudson System Information page) are NOT passed to Ant
      builds when Hudson launches a configured Ant installation.

      This does not seem intentional. Is this by design?

      For example, I declare an environment variable MYSTERY='This is a puzzler' and
      make it available in the shell by which I launch Hudson (java -jar Hudson.war)

      I add an <echo> statement in my Ant build script to print out the value of this
      env variable. When running Ant outside of Hudson, the value of MYSTERY is
      displayed properly. When running Ant inside of Hudson, the value is not
      resolved even though Hudson displays the value of MYSTERY properly in the
      Environment Variables section of the System Information page.

      This seems unexpected.
      Is this a known issue?

          [JENKINS-1640] Environment variables not passed through to Ant tasks

          kphawkins created issue -

          redsolo added a comment -

          I dont think it is intentional. But I could not reproduce your problems with 1.213.

          The steps I tried to reproduce:
          1. Execute "export MYSTERY=WORKSFORME" in shell
          2. Start hudson through java -jar hudson.war
          3. Create a new job
          4. Add a ant builder
          5. Put the following ant file into workspace
          <?xml version="1.0"?>
          <project name="test" default="a" basedir=".">
          <target name="a">
          <property environment="env" />
          <echo message="Mystery=${env.MYSTERY}"/>
          </target>
          </project>
          6. Build and check the console output:
          [workspace] $ ant a
          Buildfile: build.xml
          a:
          [echo] Mystery=WORKSFORME
          BUILD SUCCESSFUL

          Is there something Im missing?

          redsolo added a comment - I dont think it is intentional. But I could not reproduce your problems with 1.213. The steps I tried to reproduce: 1. Execute "export MYSTERY=WORKSFORME" in shell 2. Start hudson through java -jar hudson.war 3. Create a new job 4. Add a ant builder 5. Put the following ant file into workspace <?xml version="1.0"?> <project name="test" default="a" basedir="."> <target name="a"> <property environment="env" /> <echo message="Mystery=${env.MYSTERY}"/> </target> </project> 6. Build and check the console output: [workspace] $ ant a Buildfile: build.xml a: [echo] Mystery=WORKSFORME BUILD SUCCESSFUL Is there something Im missing?

          redsolo added a comment -

          Adding mail conversation

          ----------------------------------------------------------
          From Hawkins, Keith

          I must I had a typo when I tried this previously.

          The symptoms now are I can set and see in the Ant echo statement an
          environment variable MYSTERY.
          But the environment variable CLASSPATH does not resolve. Perhaps that
          is because it is being launched via java -jar hudson.war ??

          Here is the build output I see from Ant:

          deploy-QA-distribution:
          [echo] ${env.CLASSPATH}
          [echo] Can you see me

          where "Can you see me" is the value I assign to MYSTERY env variable.

          ----------------------------------------------------------
          From Erik Ramfelt

          The classpath is available as the java property "java.class.path". Are
          you sure that the CLASSPATH env variable is set when starting java
          with "-jar Hudson.war"?

          ----------------------------------------------------------
          From Hawkins, Keith

          Yes. Because I echo it out in the run.sh in which I call java -jar
          hudson.war.

          ----------------------------------------------------------
          From Erik Ramfelt

          Can you see the CLASSPATH env in the system information in Hudson? It
          seems that some environment vars are not shown in the system
          information but I dont know why.

          Does the CLASSPATH in the ant script work properly when run outside Hudson?

          ----------------------------------------------------------
          From Hawkins, Keith

          In Hudson system information, java.class.path is just hudson.war
          whereas CLASSPATH has the values I set in the run script.
          If I run the Ant build outside of Hudson, the echo task of env.CLASSPATH
          works as expected.

          Very strange.

          ----------------------------------------------------------
          From Erik Ramfelt

          Yes, but one last question. Can you echo the env variable in a shell
          in the job? ie create a shell that has "echo $CLASSPATH"

          So it seems some env variables are available in the ant scripts but
          not CLASSPATH, correct?

          redsolo added a comment - Adding mail conversation ---------------------------------------------------------- From Hawkins, Keith I must I had a typo when I tried this previously. The symptoms now are I can set and see in the Ant echo statement an environment variable MYSTERY. But the environment variable CLASSPATH does not resolve. Perhaps that is because it is being launched via java -jar hudson.war ?? Here is the build output I see from Ant: deploy-QA-distribution: [echo] ${env.CLASSPATH} [echo] Can you see me where "Can you see me" is the value I assign to MYSTERY env variable. ---------------------------------------------------------- From Erik Ramfelt The classpath is available as the java property "java.class.path". Are you sure that the CLASSPATH env variable is set when starting java with "-jar Hudson.war"? ---------------------------------------------------------- From Hawkins, Keith Yes. Because I echo it out in the run.sh in which I call java -jar hudson.war. ---------------------------------------------------------- From Erik Ramfelt Can you see the CLASSPATH env in the system information in Hudson? It seems that some environment vars are not shown in the system information but I dont know why. Does the CLASSPATH in the ant script work properly when run outside Hudson? ---------------------------------------------------------- From Hawkins, Keith In Hudson system information, java.class.path is just hudson.war whereas CLASSPATH has the values I set in the run script. If I run the Ant build outside of Hudson, the echo task of env.CLASSPATH works as expected. Very strange. ---------------------------------------------------------- From Erik Ramfelt Yes, but one last question. Can you echo the env variable in a shell in the job? ie create a shell that has "echo $CLASSPATH" So it seems some env variables are available in the ant scripts but not CLASSPATH, correct?

          Cees Bos added a comment -

          This issue also occurs on Windows batch file scripts.

          In the 'System Information' of the slave the CLASSPATH variable is available under the environment variable, but as soon as you do 'echo %CLASSPATH%' this gives you this message: 'ECHO is on.' because the CLASSPATH variable is not available at all.

          Cees Bos added a comment - This issue also occurs on Windows batch file scripts. In the 'System Information' of the slave the CLASSPATH variable is available under the environment variable, but as soon as you do 'echo %CLASSPATH%' this gives you this message: 'ECHO is on.' because the CLASSPATH variable is not available at all.
          Cees Bos made changes -
          Component/s New: core [ 15593 ]
          Component/s Original: ant [ 15488 ]

          redsolo added a comment -

          Im not sure whats wrong and I dont have much experience in the core parts.

          redsolo added a comment - Im not sure whats wrong and I dont have much experience in the core parts.
          redsolo made changes -
          Assignee Original: redsolo [ redsolo ]

          redsolo added a comment -

          Is this issue similar to the JENKINS-7442 issue?

          redsolo added a comment - Is this issue similar to the JENKINS-7442 issue?

          Alan Harder added a comment -

          Can someone post exact steps for a testcase that shows the problem in the latest Jenkins release? I did recently make more Jenkins-defined vars get expanded in ant build steps, but I don't think that is related here as you're talking about vars defined in the external environment.

          Alan Harder added a comment - Can someone post exact steps for a testcase that shows the problem in the latest Jenkins release? I did recently make more Jenkins-defined vars get expanded in ant build steps, but I don't think that is related here as you're talking about vars defined in the external environment.

          dmeibusch added a comment -

          With Jenkins 1.408, we do see most of the environment variables inherited from the slave and/or configured being available in the Ant build step with the exception of the CLASSPATH variable. Presumably, a special case?

          dmeibusch added a comment - With Jenkins 1.408, we do see most of the environment variables inherited from the slave and/or configured being available in the Ant build step with the exception of the CLASSPATH variable. Presumably, a special case?

            Unassigned Unassigned
            kphawkins kphawkins
            Votes:
            7 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: