Ant和Github与Jenkins的集成

时间:2015-06-25 12:41:25

标签: github ant jenkins

我没有找到任何指定的链接来处理Jenkins与ANT和GitHub的集成。如果有人知道,请说明。

我希望在使用Jenkins时,只要在GitHub中出现新的更改,就可以使用ANT构建war文件。 我面临以下错误:

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

我已经通过File-> Export-> General-> Buildfile生成了ANT build.xml文件。

以下是build.xml文件的代码:

<?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>

该项目是一个普通的动态Web项目,我将其推入GitHub。

1 个答案:

答案 0 :(得分:1)

我有解决方案。我没有导出build.xml文件,而是单独创建了一个XML文件,并添加了所需的目标来获取war文件。

导出构建文件可能在命令提示符下支持,但在Jenkins中不支持。