1

嗨,我是 jenkins/ant/groovy 世界的新手,谷歌无法帮助我解决我的问题。

我的任务是在构建过程中摆脱 ant 脚本(使用 jenkins)并将它们包含到 jenkins 作业中(执行系统 ​​Groovy 脚本)。

我脚本的粗体部分是失败的原因,但我不知道如何解决这个问题。

我希望有人可以帮助我解决这个问题。

这是我的“执行系统 ​​Groovy 脚本”:

antbuild = new AntBuilder()
projectHome = '...Homedirectory'

projectDomainModel = projectHome + '/CSSDomainModel'
projectPresentationBase = projectHome + '/CSSPresentationBase'
projectServices = projectHome + '/CSSServices'
projectResource = projectHome + '/src/main/resources'

Sources = projectHome + '/Presentation/JavaSource'
projectLibraries = 'lib/bin'
projectWebContent = projectHome + '/Presentation/WebContent'
projectWebInf = projectWebContent + '/WEB-INF'

deployHome = projectHome + '/target/servicekundenportal'
deployBuild = deployHome + '/build/classes'
deployWebInf = deployHome + '/WEB-INF'

foreignSources = 'src'

deployWARFile = deployHome + '/serviceportal.war'

j2eeLibraries = 'D:/Programme_x64/tomcat/8.0.21/Instanz_02/lib'
compileTarget = '1.8'

<b>compilerSourceFiles = antbuild.path{
        pathelement(path:Sources)
        pathelement(path:projectDomainModel + '/' + foreignSources)
        pathelement(path:projectPresentationBase + '/' + foreignSources)
        pathelement(path:projectServices + '/' + foreignSources)
        }

compilerLibraryFiles = antbuild.path{
        fileset(dir:projectDomainModel + '/' + projectLibraries) {include name:'**/*.jar'}
        fileset(dir:projectPresentationBase + '/' + projectLibraries) {include name:'**/*.jar'}
        fileset(dir:projectServices + '/' + projectLibraries) {include name:'**/*.jar'}
        fileset(dir:j2eeLibraries) {include name:'**/*.jar'}
        }</b>

antbuild.delete(dir:deployHome)
antbuild.delete(file:deployWARFile)
antbuild.mkdir(dir:deployBuild)

build() {   

        antbuild.javac(
            destdir:deployBuild,
            target:compileTarget,
            debug:true,
            fork:true,
            executable:'D:/Programme_x64/Java/jdk1.8.0_45/bin/javac')<b>{
                src(path:compilerSourceFiles)
                classpath(path:compilerLibraryFiles)
                }</b>
        }

build()

我无法转换的 Ant 脚本部分:

<!-- Compiler Source File Definition -->
    <path id="compilerSourceFiles">
        <pathelement path="${Sources}" />
        <pathelement path="${projectDomainModel}/${foreignSources}" />
        <pathelement path="${projectPresentationBase}/${foreignSources}" />
        <pathelement path="${projectServices}/${foreignSources}" />
    </path>

    <!-- Compiler Library Definition -->
    <path id="compilerLibraryFiles">
        <fileset id="librariesDomainModel" dir="${projectDomainModel}/${projectLibraries}">
            <include name="**/*.jar" />
        </fileset>
        <fileset id="librariesPresentationBase" dir="${projectPresentationBase}/${projectLibraries}">
            <include name="**/*.jar" />
        </fileset>
        <fileset id="librariesServices" dir="${projectServices}/${projectLibraries}">
            <include name="**/*.jar" />
        </fileset>
        <fileset dir="${j2eeLibraries}">
            <include name="**/*.jar" />
        </fileset>
    </path>



    <target name="executeCompiler" depends="preCompile">
            <javac destdir="${deployBuild}" target="${compileTarget}"
                debug="true" debuglevel="lines,vars" encoding="ISO8859-1">
                <src refid="compilerSourceFiles" />
                <classpath refid="compilerLibraryFiles" />
            </javac>
        </target>
4

1 回答 1

0

您的示例对本地目录结构等有太多依赖项,无法完全复制,但是使用类似下面的内容作为模式应该可以让您朝着正确的方向前进:

def ant = new AntBuilder()

def projectHome = '...Homedirectory'

ant.path(id: 'compilerSourceFiles') {
  pathelement(path: "$projectHome/Presentation/JavaSource")
  pathelement(path: "$projectHome/CSSDomainModel/src")
  pathelement(path: "$projectHome/CSSPresentationBase/src")
  pathelement(path: "$projectHome/CSSServices/src")
}

ant.path(id: "compilerSourceFiles") {
  fileset(id: "librariesDomainModel", dir: "$projectHome/CSSDomainModel/lib/bin") {
    include(name: "**/*.jar")
  }
  fileset(id: "librariesPresentationBase", dir: "....") {
    include(name: "**/*.jar")
  }
  //...
}

ant.target(name: 'executeCompiler', depends: 'preCompile') {
  javac(destDir: "...", target: "...", debug: true, debugLevel: "lines,vars", encoding: "...") {
    src(refid: "compilerSourceFiles")
    classpath(refid: "compilerLibraryFiles")
  }
}

换句话说,每个 ant xml 片段:

<outerelement outerattribute="outervalue"> 
    <innerelement innerattribute="innervalue" />
</outerelement> 

转换为:

ant.outerelement(outerattribute: "outervalue") {
    innerelement(innerattribute: "innervalue")
}

使用 AntBuilder 时。

于 2017-02-24T10:59:01.190 回答