基于teamcity的持续集成实践(ant脚本2)
上一篇,说到了ant脚本如何分类以及何组织的,现在让我们看一下如何用ant脚本来实现上面所说的过程。
在此同样先是基于小的分类,然后是整合,其实按照上篇的分类是非常细的,因此对于一些经常用到的,在此就不赘述,仅说几个我认为不常用的,但是很关键的。
首先定义weblogic的相关ant任务
<path id="weblogic.ant.classpath">
<pathelementlocation="${weblogic.home}/server/lib/weblogic.jar"/>
</path><target name="init" description="">
<taskdefname="wlserver"classname="weblogic.ant.taskdefs.management.WLServer"classpathref="weblogic.ant.classpath"/>
<taskdefname="wlconfig"classname="weblogic.ant.taskdefs.management.WLConfig"classpathref="weblogic.ant.classpath"/>
<taskdefname="wldeploy"classname="weblogic.ant.taskdefs.management.WLDeploy"classpathref="weblogic.ant.classpath"/>
</target>然后是weblogic的启动与关闭,此处并没有通过wlserver来进行weblogic的startup与shutdown,是因为在我的环境里面总是报错,实在解决不了了,就采用了如下的这种替代方案。
<target name="startup">
<echomessage="--------StartingWeblogicAdminServer-----"/>
<execexecutable="${domain.home}/startWebLogic.sh">
</exec>
<echomessage="${weblogic.adminserver}startedsuccessfully"/>
</target><target name="shutdown">
<echomessage="--------ShutdownWeblogicserver--------"/>
<execexecutable="${domain.home}/bin/stopWebLogic.sh"/>
<sleepseconds="20"/>
</target>接下来是创建weblogic domain
<target name="create-test" depends="init" description="">
<echomessage="--------Createweblogicdomain:odmain--------"/>
<deletedir="${domain.home}"/>
<mkdirdir="${domain.home}"/>
<wlserver
weblogichome="${weblogic.home}"
username="${weblogic.username}"
password="${weblogic.password}"
servername="${weblogic.adminserver}"
domainname="${domain.name}"
dir="${domain.home}"
host="${weblogic.host}"
port="${weblogic.port.adminserver}"
productionmodeenabled="${weblogic.domain.isproduction}"
generateconfig="true"
classpath="${weblogic.jar}:${java.home}/lib/tools.jar">
<jvmargvalue="-server"/>
<jvmargvalue="-Xms256m"/>
<jvmargvalue="-Xmx512m"/>
<jvmargvalue="-XX:PermSize=128m"/>
<jvmargvalue="-XX:MaxPermSize=256m"/>
<jvmargvalue="-Dweblogic.ThreadPoolPercentSocketReaders=75"/>
<jvmargvalue="-Djava.security.policy=${weblogic.home}/server/lib/weblogic.policy"/>
</wlserver>
</target>再接下来是配置weblogic domain
<target name="config-test" description="Add Weblogic domain DB/JMS configurations" depends="init">
<echomessage="--------Configalldomainweblogicresources--------"/>
<mkdirdir="${domain.home}/rmfilestore"/>
<wlconfigurl="t3://${weblogic.host}:${weblogic.port.adminserver}"
username="${weblogic.username}"password="${weblogic.password}">
<querydomain="${domain.name}"type="Server"name="${weblogic.adminserver}"
property="prop.admin.server"/>
<createtype="JDBCConnectionPool"name="TestConnectionPool">
<setattribute="InitialCapacity"value="${jdbc.pool.initcapacity}"/>
<setattribute="CapacityIncrement"value="1"/>
<setattribute="MaxCapacity"value="${jdbc.pool.maxcapacity}"/>
<setattribute="DriverName"value="${oracle.driver}"/>
<setattribute="Properties"value="user=${oracle.username.core2}"/>
<setattribute="Password"value="${oracle.password.core2}"/>
<setattribute="TestConnectionsOnRelease"value="true"/>
<setattribute="TestConnectionsOnReserve"value="true"/>
<setattribute="URL"value="${oracle.url.core2}"/>
<setattribute="TestTableName"value="SQLSELECT1FROMDUAL"/>
<setattribute="Targets"value="${prop.admin.server}"/>
</create>
<createtype="JDBCDataSource"name="TestDataSource">
<setattribute="JNDIName"value="${datasource.jndi.name.test}"/>
<setattribute="PoolName"value="TestConnectionPool"/>
<setattribute="Targets"value="${prop.admin.server}"/>
</create>
<createtype="JMSConnectionFactory"name="jms/JMSConnectionFactory">
<setattribute="JNDIName"value="jms/JMSConnectionFactory"/>
<setattribute="XAConnectionFactoryEnabled"value="true"/>
<setattribute="DefaultDeliveryMode"value="Non-Persistent"/>
<setattribute="Targets"value="${prop.admin.server}"/>
</create>
<createtype="JMSFileStore"name="TestPersistentStore"property="test.persist.store">
<setattribute="Directory"value="rmfilestore"/>
</create>
<createtype="JMSFileStore"name="TestPagingStore"property="test.paging.store">
<setattribute="Directory"value="rmfilestore"/>
</create>
<createtype="JMSServer"name="TestJMSServer">
<setattribute="Store"value="${test.persist.store}"/>
<setattribute="PagingStore"value="${test.paging.store}"/>
<setattribute="Targets"value="${prop.admin.server}"/>
<createtype="JMSQueue"name="jms/TestQueue">
<setattribute="JNDIName"value="jms/TestQueue"/>
</create>
<createtype="JMSTopic"name="jms/TestTopic">
<setattribute="JNDIName"value="jms/TestTopic"/>
</create>
</create>
</wlconfig>
</target>再接下来是deploy
<target name="deploy-test" depends="init">
<echomessage="--------Deployallodomainwarandear--------"/>
<wldeployaction="deploy"source="${deploy.package.folder}/od/test.ear"name="test"
user="${weblogic.username}"password="${weblogic.password}"verbose="true"nostage="false"
adminurl="t3://${weblogic.host}:${weblogic.port.adminserver}"targets="${weblogic.adminserver}">
</wldeploy>
<wldeployaction="deploy"source="${deploy.package.folder}/od/portal.war"name="portal"
user="${weblogic.username}"password="${weblogic.password}"verbose="true"nostage="false"
adminurl="t3://${weblogic.host}:${weblogic.port.adminserver}"targets="${weblogic.adminserver}"/>
</target>最后,findbugs
<target name="findbugs-test">
<findbugshome="${findbugs.home}"
output="xml"
outputFile="findbugs/findbugs-test.xml"
jvmargs="-Xmx640m">
<auxClasspath>
<filesetdir="${basedir}/test/lib">
<includename="*.jar"/>
</fileset>
<pathelementlocation="${emma.jar}"/>
</auxClasspath>
<sourcePathpath="${basedir}/test/src"/>
<classlocation="${basedir}/test/dist/classes"/>
</findbugs>
</target>有了这些分类以后,我们就简单得按照上篇的想法来进行组织,此处仅组织持续集成的,项目创建的根据各自不同可以自己组织。
<target name="ci" description="">
<antcalltarget="build-test"/>
<antcalltarget="findbugs-test"/>
<parallel>
<antcalltarget="startup"/>
<sequential>
<waitformaxwait="5"maxwaitunit="minute"checkevery="1"checkeveryunit="second">
<httpurl="http://${weblogic.host}:${weblogic.port.adminserver}"/>
</waitfor>
<antcalltarget="integration-test"/>
<antcalltarget="shutdown"/>
</sequential>
</parallel>
</target>