3

Every time I try to invoke an Ant build file from the command line I get an error:

Unable to write log file

Am I missing something here? Please let me know as I am trying to run my Junit batch files from a command prompt using Ant.

<?xml version="1.0" encoding="UTF-8"?>
<project name="AntTest"  basedir=".">
  <description>
    AntTest project build file.
  </description>

  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="bin"/>
  <property name="ExternalLibraries" location="ExternalLibraries"/>
  <property name="JenkinsResults" location="Results/JenkinsResults"/> 
  <property name="TestSuiteName" location="${src}/AntTest.testsuite"/>

  <!--Set the classpath for compiling the source files-->   
  <path id="AntTest.classpath">
        <fileset dir="${ExternalLibraries}">
         <include name="**/*.jar"/>
        </fileset>
        <pathelement location="${build}"/>
        <pathelement location="${Results}"/>
  </path>  

  <!--Set the framework properties required for the run-->
  <target name="setFrameworkProperties">
    <propertyfile file="framework.properties" >
        <entry key="browser" operation="=" value="${Browser}" />
        <entry key="url" operation="=" value="${Url}" />
        <entry key="Environment" operation="=" value="${Environment}" />    
    </propertyfile>   
  </target>

  <!--Creates the directory for the classes-->  
  <target name="createBuildFolder" depends="setFrameworkProperties">
    <mkdir dir="${build}"/>
  </target> 

  <!--Creates the Jenkins results folder--> 
  <target name="createResultsFolder" depends="createBuildFolder">
    <mkdir dir="${JenkinsResults}"/>    
  </target>

    <!--Deletes the old build jenkins results files-->  
       <target name="DeleteContentsOldResultsFolder" depends="createResultsFolder">
           <delete>
                <fileset dir="${JenkinsResults}">
                    <include name="**/*.*"/>
                </fileset>
            </delete> 
        </target>

  <!--Compile the source code from the source folder to the build folder--> 
  <target name="compile" depends="DeleteContentsOldResultsFolder" description="compile the source " >

   <!-- Compile the java code from ${src} into ${build} -->
   <javac srcdir="${src}" destdir="${build}" includeantruntime="false">
   <classpath refid="AntTest.classpath" />
   </javac>
  </target>  

  <target name="runtestsuite" description="runs a junit testsuite" >
   <antcall id="compileTargetCall" description="Call to target compile" target="compile"/>

   <!-- runs a testsuite -->
   <junit printsummary="yes" haltonfailure="no">
      <classpath refid="AntTest.classpath" />
      <test name="${TestSuiteName}" haltonfailure="no" todir="${JenkinsResults}">
      <formatter type="xml"/>
      </test>
   </junit> 
   <antcall id="deleteBuildFolderCall" description="Call to delete build folder" target="deleteBuildFolder" />
  </target>

  <!--Deletes the directory for the classes after the current run-->    
  <target name="deleteBuildFolder">
    <delete dir="${build}"/>
  </target>
</project>
Chad Nouis
  • 6,861
  • 1
  • 27
  • 28
  • 1
    Could you add the error output, please. – Stefan Birkner Apr 04 '16 at 10:23
  • BUILD FAILED C:\Auto\workspace\AntTest\build.xml:68: Unable to write log file Hi Stefan, This is the error am getting – Raj Hiremath Apr 04 '16 at 10:26
  • Also note that if you specified that Ant should write into a custom directory, this directory must exist because **the junit task will not create it as opposed to the javadoc task.** – SEJPM Feb 09 '17 at 22:06

2 Answers2

0

It looks like not much information is printed on exception. On browsing i came to now this which helps you get more details on exception.

One more thing is did you using log4j or any reference to it. you can check this to get out off reference to log4j

Thank You, Murali

Community
  • 1
  • 1
murali selenium
  • 3,847
  • 2
  • 11
  • 20
0

I have resolved the above error with some trial and error but not sure whether this will work 100% for others or not, but what I did I am sharing my experience.

Steps

  1. service jenkins stop or sudo /etc/init.d/jenkins stop
  2. Make sure all services are stopped. Even u should not be able to access the jenkins url from browser.
  3. check the rpm -qa|grep jenkins. It will show your jenkins rpm package.
  4. Run the find / -name jenkins to check where and all jenkins is used.

    [root@localhost]# find / -name "jenkins"

    /etc/rc.d/init.d/jenkins

    /etc/logrotate.d/jenkins

    /etc/sysconfig/jenkins

    /usr/lib/jenkins

    /var/lib/jenkins

    /var/cache/jenkins

    /var/cache/yum/jenkins

    /var/log/jenkins

    [root@localhost]#

  5. Take backup of /var/lib/jenkins/ folders to /var/lib/jenkins.old

  6. Now run the "rpm -e --nodeps jenkins-1.651.3-1.1" to remove the package.

  7. Repeat Step 4 again and make sure /var/cache/jenkins and /var/cache/yum/jenkins are the two directories which remains

  8. Now run "rpm -ivh /etc/yum.repos.d/jenkins-1.651.3-1.1.noarch.rpm" to install the jenkins package

  9. Run "service jenkins start" so that it will listen on port 8080

  10. Open the jenkins url with IP and Port.

  11. Create a free-style project with some name and make sure the project should be created in /var/lib/jenkins/jobs/project_name

  12. Configure the necessary steps such as JDK Installation, Ant installations etc., in manage jenkins options.

  13. Now run the build for your project without configuring build.xml path, so that it will create a workspace folder in /var/lib/jenkins/workspace/project_name

  14. Now copy the build.xml file from existing project and put the file in /var/lib/jenkins/workspace/project_name

  15. Build project from Jenkins.

  16. Try to resolve script label errors such as it will complain for lib, src folders not found and copy/create those folders to resolve the compilation errors.

  17. Once done with all errors try to run the build again so that you will get Build Successful.

  18. Make sure you copy/create src and lib folder and don't copy/create the target folder.

  19. Make sure target folder must be created automatically by Jenkins with jenkins ownership and jenkins file permission. Rest all may be root owner and root file permission.

  20. Now configure the junit report and email notifications to get the build reports in email.

Chinmoy
  • 493
  • 1
  • 5
  • 16