1
votes

I have not found any specified links to work on integration of Jenkins with ANT and GitHub. If anybody knows, please specify.

I want to build a war file with ANT, whenever a new change appears in GitHub, by using Jenkins. I am facing the following error:

Started by an SCM change
Building in workspace C:\Program Files\Jenkins\jobs\ANTwithGitIntegration\workspace
 > C:\Program Files\Git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > C:\Program Files\Git\bin\git.exe config remote.origin.url https://github.com/swethasreeramoju/ANTGitIntegration.git # timeout=10
Fetching upstream changes from https://github.com/swethasreeramoju/ANTGitIntegration.git
 > C:\Program Files\Git\bin\git.exe --version # timeout=10
using .gitcredentials to set credentials
 > C:\Program Files\Git\bin\git.exe config --local credential.helper store --file=\"C:\Windows\TEMP\git2414419353538628866.credentials\" # timeout=10
 > C:\Program Files\Git\bin\git.exe -c core.askpass=true fetch --tags --progress https://github.com/swethasreeramoju/ANTGitIntegration.git +refs/heads/*:refs/remotes/origin/*
 > C:\Program Files\Git\bin\git.exe config --local --remove-section credential # timeout=10
 > C:\Program Files\Git\bin\git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
 > C:\Program Files\Git\bin\git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision d5143b19bc850c9e9f1d498c423fb96b777cbf55 (refs/remotes/origin/master)
 > C:\Program Files\Git\bin\git.exe config core.sparsecheckout # timeout=10
 > C:\Program Files\Git\bin\git.exe checkout -f d5143b19bc850c9e9f1d498c423fb96b777cbf55
 > C:\Program Files\Git\bin\git.exe rev-list cfdc3ab5d2a36dfeabda376ba3dc27b2e60f2e5e # timeout=10
[ANTRepositoryIntegration] $ cmd.exe /C '"C:\apache-ant-1.9.5\bin\ant.bat -file build.xml war && exit %%ERRORLEVEL%%"'
Buildfile: C:\Program Files\Jenkins\jobs\ANTwithGitIntegration\workspace\ANTRepositoryIntegration\build.xml
     [echo] C:\Program Files\Jenkins\jobs\ANTwithGitIntegration\workspace

clean:
   [delete] Deleting directory C:\Program Files\Jenkins\jobs\ANTwithGitIntegration\workspace\ANTRepositoryIntegration\build\classes

build-subprojects:

init:
    [mkdir] Created dir: C:\Program Files\Jenkins\jobs\ANTwithGitIntegration\workspace\ANTRepositoryIntegration\build\classes

build-project:
     [echo] ANTRepositoryIntegration: C:\Program Files\Jenkins\jobs\ANTwithGitIntegration\workspace\ANTRepositoryIntegration\build.xml

BUILD FAILED
C:\Program Files\Jenkins\jobs\ANTwithGitIntegration\workspace\ANTRepositoryIntegration\build.xml:61: srcdir "C:\Program Files\Jenkins\jobs\ANTwithGitIntegration\workspace\ANTRepositoryIntegration\.apt_generated" does not exist!

Total time: 0 seconds
Build step 'Invoke Ant' marked build as failure
Finished: FAILURE

I have Generated the ANT build.xml file by File->Export->General->Buildfile.

And Below is the code of build.xml file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply create one in the same
              directory with the processing instruction <?eclipse.ant.import?>
              as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="ANTRepositoryIntegration">
    <property environment="env"/>
    <echo message="${env.WORKSPACE}" />
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.6"/>
    <property name="source" value="1.6"/>
    <path id="Apache Tomcat v7.0 [Apache Tomcat v7.0].libraryclasspath">  
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/annotations-api.jar"/> 
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/catalina-ant.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/catalina-ha.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/catalina-tribes.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/catalina.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/ecj-P20140317-1600.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/el-api.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/jasper-el.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/jasper.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/jsp-api.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/servlet-api.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-api.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-coyote.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-dbcp.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-i18n-es.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-i18n-fr.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-i18n-ja.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-jdbc.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-util.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat7-websocket.jar"/>
        <pathelement location="C:/Program Files/Apache Software Foundation/Tomcat 7.0/lib/websocket-api.jar"/>
    </path>
    <path id="ANTRepositoryIntegration.classpath">
        <pathelement location="build/classes"/>
        <path refid="Apache Tomcat v7.0 [Apache Tomcat v7.0].libraryclasspath"/>
    </path>
    <target name="init">
        <mkdir dir="build/classes"/>
        <copy includeemptydirs="false" todir="build/classes">
            <fileset dir="src">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
        <copy includeemptydirs="false" todir="build/classes">
            <fileset dir=".apt_generated">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    <target name="clean">
        <delete dir="build/classes"/>
    </target>
    <target depends="clean" name="cleanall"/>
    <target depends="build-subprojects,build-project" name="build"/>
    <target name="build-subprojects"/>
    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="build/classes" includeantruntime="false" source="${source}" target="${target}">
            <src path="src"/>
            <src path=".apt_generated"/>
            <classpath refid="ANTRepositoryIntegration.classpath"/>
        </javac>
    </target>
    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>

    <target name="war" description="Bundles the application as a WAR file" depends="clean, build">
        <mkdir dir="WebContent/WEB-INF/classes"/>

        <copy includeemptydirs="false" todir="WebContent/WEB-INF/classes">
                <fileset dir="build/classes">
                <include name="**/*.class"/>
                </fileset>
        </copy>

        <war destfile="ANTRepositoryIntegration.war"
            basedir="WebContent"
            needxmlfile="false">
        </war>
    </target>
</project>

The project is a normal Dynamic Web Project which I am pushing it into GitHub.

1
But what exactly is your problem? There a dozens of tutorials how to trigger builds in Jenkins for any supported SCM and dozens of tutorials on how to build "whatever" using ANT, it even provides as special "war" task. Put both together and cook your meal...Thorsten Schöning
Edited the question.swetha

1 Answers

1
votes

I have got the solution. Instead of exporting the build.xml file, I created an XML file separately and added the required targets to get a war file.

Exporting the build file may support in command prompt, but not in Jenkins.