【问题标题】:Integration of Ant and Github with JenkinsAnt 和 Github 与 Jenkins 的集成
【发布时间】:2015-06-26 13:34:31
【问题描述】:

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

每当 GitHub 中出现新更改时,我想使用 Jenkins 使用 ANT 构建一个战争文件。 我面临以下错误:

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。

【问题讨论】:

  • 但是你的问题到底是什么?有几十个教程如何在 Jenkins 中为任何受支持的 SCM 触发构建,还有几十个关于如何使用 ANT 构建“任何东西”的教程,它甚至提供了特殊的“战争”任务。把两者放在一起做饭……
  • 编辑了问题。

标签: github ant jenkins


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-19
    • 2017-12-05
    • 2021-08-20
    • 1970-01-01
    • 1970-01-01
    • 2011-03-29
    相关资源
    最近更新 更多