使用ant进行自动daily build.

环境说明:我用的是weblogic81sp5+apache ant 1.6.5+wincvs2.0.

全部代码:

dailybuild.xml:该xml适用范围

1)weblogic 环境.我的环境是cluster 下的管理服务器.管理服务器是挂在nodemanage下的.(后面会补充关于直接启动非nodemanager管理的管理服务器.)

<? xmlversion="1.0" ?>
< project name ="SPprojectantAutobuildscript" basedir ="." default ="build" >

<!-- Initializing -->
< property file ="dailybuild.properties" />
< property name ="cvsroot" value ="${cvs.root}" />
< property name ="cvspassword" value ="${cvs.password}" />
< property name ="fs.module.name" value ="${cvs.fs.module}" />
< property name ="fw.module.name" value ="${cvs.fw.module}" />
< property name ="sportal.module.name" value ="${cvs.sportal.module}" />

<!-- propertiesforremoteweblogicdepoly -->
< property name ="weblogic.servername" value ="${weblogic.servername}" />
< property name ="deploy.servername" value ="${deploy.servername}" />
< property name ="weblogic.adminurl" value ="${weblogic.adminurl}" />
< property name ="weblogic.home" value ="${bea.home}/weblogic81" />
< property name ="weblogic.lib" value ="${weblogic.home}/server/lib" />
< property name ="weblogic.version" value ="${weblogic.version}" />
< property name ="weblogic.username" value ="${weblogic.username}" />
< property name ="weblogic.password" value ="${weblogic.password}" />
< property name ="weblogic.domain" value ="${weblogic.domain}" />
< property name ="weblogic.domain.dir" value ="${bea.home}/user_projects/domains/vigdomain" />
< property name ="weblogic.config.dir" value ="${weblogic.domain.dir}" />
< property name ="weblogic.config.name" value ="config.xml" />
< property name ="portal.war.lib" value ="${weblogic.home}/common/nodemanager/vigserver/stage/portal/portal.war/WEB-INF/lib" />

< property name ="portlet.deployment.dir" value ="${basedir}SPORTALuild" />

< taskdef name ="wldeploy" classname ="weblogic.ant.taskdefs.management.WLDeploy" >
< classpath location ="${weblogic.lib}/weblogic.jar" />
</ taskdef >
< taskdef name ="wlserver" classname ="weblogic.ant.taskdefs.management.WLServer" >
< classpath location ="${weblogic.lib}/weblogic.jar" />
</ taskdef >

< tstamp >
< format property ="today" pattern ="yyyy-MM-dd" />
</ tstamp >
< echo message ="${today}" />

< mkdir dir ="logs" />
<!-- infologs -->
< record name ="${basedir}/logs/${today}_daily_build_info_log.txt" loglevel ="info" />
<!-- errorlogs -->
< record name ="${basedir}/logs/${today}_daily_build_error_log.txt" loglevel ="error" />

<!-- Retrievethemodules -->
< target name ="check-out-fs" >
< delete dir ="${fs.module.name}" />
< cvs cvsRoot ="${cvsroot}" package ="${fs.module.name}" command ="checkout${fs.module.name}" />
</ target >
< target name ="check-out-fw" >
< delete dir ="${fw.module.name}" />
< cvs cvsRoot ="${cvsroot}" package ="${fw.module.name}" command ="checkout${fw.module.name}" />
</ target >
< target name ="check-out-sportal" >
< delete dir ="${sportal.module.name}" />
< cvs cvsRoot ="${cvsroot}" package ="${sportal.module.name}/build.xml" command ="checkout${sportal.module.name}/build.xml" />
</ target >

<!-- cvscheckout -->
< target name ="check-out" >
< antcall target ="check-out-fs" />
< antcall target ="check-out-fw" />
< antcall target ="check-out-sportal" />
</ target >

<!-- buildXSPframework -->
< target name ="build" >
< antcall target ="build-all" />
</ target >

< target name ="build-all" depends ="check-out" >
< antcall target ="do.subant.buildall" >
< param name ="target.name" value ="release" />
</ antcall >
< antcall target ="archive" />
< antcall target ="reboot-server" />
< antcall target ="deploywartoServer" />
< antcall target ="reboot-server" />
</ target >

< target name ="do.subant.buildall" >
< subant target ="${target.name}" >
< filelist dir ="${basedir}SPORTAL" >
< file name ="" />
</ filelist >
</ subant >
</ target >

< target name ="deploywartoServer" description ="Deploytoweblogic" >
< echo message ="Deployed${portlet.warfile.name}toWeblogicAppServer" />
< wldeploy action ="deploy" source ="${infoboard.remote.server}/${portlet.warfile.name}" name ="${portlet.app.name}" debug ="true" targets ="${deploy.servername}" adminurl ="${weblogic.adminurl}" user ="${weblogic.username}" password ="${weblogic.password}" />
</ target >

< target name ="archive" >
< echo message ="${portlet.deployment.dir}/${portlet.warfile.name}" />
< echo message ="deletestart" />
< delete file ="${infoboard.remote.server}/${portlet.warfile.name}" />
< delete file ="${ui.remote.dir}/${uim.carfile.name}" />
< delete file ="${ui.remote.dir}/${spui.carfile.name}" />
<!-- <deletefile="${portal.war.lib}/healthcheck_monitor.jar"/>
<deletefile="${portal.war.lib}/HPPWebServicesFramework.jar"/>
<deletefile="${portal.war.lib}/ServicePortalSSO.jar"/>
<deletefile="${portal.war.lib}/SPCommonUtils.jar"/>
<deletefile="${portal.war.lib}/SPHPPTaglibs.jar"/>
-->
< echo message ="deletefinish" />
< copy file ="${portlet.deployment.dir}/${uim.carfile.name}" todir ="${ui.remote.dir}" />
< copy file ="${portlet.deployment.dir}/${spui.carfile.name}" todir ="${ui.remote.dir}" />
< copy file ="${portlet.deployment.dir}/${portlet.warfile.name}" todir ="${infoboard.remote.server}" />
<!-- <copyfile="${portlet.deployment.dir}/healthcheck_monitor.jar"todir="${portal.war.lib}"/>
<copyfile="${portlet.deployment.dir}/HPPWebServicesFramework.jar"todir="${portal.war.lib}"/>
<copyfile="${portlet.deployment.dir}/ServicePortalSSO.jar"todir="${portal.war.lib}"/>
<copyfile="${portlet.deployment.dir}/SPCommonUtils.jar"todir="${portal.war.lib}"/>
<copyfile="${portlet.deployment.dir}/SPHPPTaglibs.jar"todir="${portal.war.lib}"/>
-->
</ target >

< path id ="weblogic.classpath" >
< pathelement path ="${java.classpath}" >
</ pathelement >
< fileset dir ="${weblogic.lib}" >
< include name ="weblogic.jar" >
</ include >
< include name ="ojdbc14.jar" >
</ include >
< include name ="wlclient.jar" >
</ include >
< include name ="webservices.jar" >
</ include >
</ fileset >
< fileset dir ="${vignette.server.path}/lib/shared" >
< include name ="portlet.jar" />
< include name ="vgn-jsr-container-shared.jar" />
< include name ="vgn-jsr-container-taglib.jar" />
< include name ="vgn-portal-config.jar" />
< include name ="vgn-portal-log-spi.jar" />
< include name ="vgn-portal-naming-portlet.jar" />
< include name ="vgn-portal-shared.jar" />
< include name ="vgn-portlet-app-registry.jar" />
</ fileset >
< fileset dir ="${vignette.server.path}/lib/ext" >
< include name ="jms.jar" />
< include name ="servlet.jar" />
< include name ="vgn-portal-discussionmigration.jar" />
</ fileset >
< fileset dir ="${vignette.server.path}/lib" >
< include name ="oracle.jar" >
</ include >
< include name ="mail.jar" >
</ include >
</ fileset >
< fileset dir ="${weblogic.home}/common/eval/pointbase/lib" >
< include name ="pbclient44.jar" />
< include name ="pbserver44.jar" />
< include name ="pbtools44.jar" />
</ fileset >
</ path >
<!--
<targetname="stop-server">
<echomessage="******************************************************"/>
<echomessage="Stoptheweblogicmanagedserver"/>
<wlserverhost="localhost"port="7003"username="${weblogic.username}"password="${weblogic.password}"action="shutdown"forceshutdown="true"/>
<echomessage="******************************************************"/>
<echomessage="OK.Stoptheweblogicmanagedserversuccessfully"/>
</target>
-->
< target name ="reboot-server" description ="Startsamanagedserver" >
<!-- NeedtoinvokelookupNodeManagerRuntimebeforewecanlookuptheruntimembean -->
< java classname ="weblogic.Admin" failonerror ="false" fork ="true" classpathref ="weblogic.classpath" >
< arg line ="-url${weblogic.adminurl}" />
< arg line ="-username${weblogic.username}" />
< arg line ="-password${weblogic.password}" />
< arg line ="INVOKE" />
< arg line ="-mbean${weblogic.domain}:Name=${weblogic.machine},Type=Machine" />
< arg line ="-methodlookupNodeManagerRuntime" />
</ java >

< java classname ="weblogic.Admin" failonerror ="false" fork ="true" classpathref ="weblogic.classpath" >
< arg line ="-url${weblogic.adminurl}" />
< arg line ="-username${weblogic.username}" />
< arg line ="-password${weblogic.password}" />
< arg line ="-mbean${weblogic.domain}:Location=${weblogic.adminservername},Name=${weblogic.machine},ServerRuntime=${weblogic.adminservername},Type=NodeManagerRuntime" />
< arg line ="stopcluster-clusternamevigcluster" />
</ java >

<!-- LookuptheNodeManagerRuntimeMBeanandgivethecommandtostartit. -->
< java classname ="weblogic.Admin" failonerror ="false" fork ="true" classpathref ="weblogic.classpath" >
< arg line ="-url${weblogic.adminurl}" />
< arg line ="-username${weblogic.username}" />
< arg line ="-password${weblogic.password}" />
< arg line ="-mbean${weblogic.domain}:Location=${weblogic.adminservername},Name=${weblogic.machine},ServerRuntime=${weblogic.adminservername},Type=NodeManagerRuntime" />
< arg line ="startcluster-clusternamevigcluster" />
</ java >
</ target >

<!--
<targetname="start-server"depends="stop-server">
<javaclassname="weblogic.Server"fork="yes"classpathref="weblogic.classpath"failonerror="true">
<syspropertykey="weblogic.Domain"value="${weblogic.domain}">
</sysproperty>
<syspropertykey="weblogic.NodeManager"value="${weblogic.home}/commom/nodemanager">
</sysproperty>
<syspropertykey="weblogic.RootDirectory"value="${weblogic.config.dir}">
</sysproperty>
<syspropertykey="weblogic.ConfigFile"value="${weblogic.config.name}">
</sysproperty>
<syspropertykey="weblogic.ListenPort"value="7003">
</sysproperty>
<syspropertykey="weblogic.ListenAddress"value="">
</sysproperty>
<syspropertykey="weblogic.management.server"value="${weblogic.adminurl}">
</sysproperty>
<syspropertykey="java.security.policy"value="${weblogic.home}/server/lib/weblogic.policy">
</sysproperty>
<syspropertykey="weblogic.Name"value="${weblogic.servername}">
</sysproperty>
<argline="-ms32m-mx200m">
</arg>
<argline="-Xnohup">
</arg>
<jvmargvalue="-Dcom.vignette.portal.installdir.path=C:VignettePortal"/>
</java>
<wlserverbeahome="${bea.home}"weblogichome="${weblogic.home}"dir="${weblogic.domain.dir}"adminserverurl="${weblogic.adminurl}"servername="vigcluster"username="${weblogic.username}"password="${weblogic.password}"action="reboot"/>
</target>
-->
<!--
<targetname="deploytoTomcat"depends="archive"description="Deploytotomcat">
<echomessage="DeployedexpandedwebarchivetoTomcat"/>
<copytodir="D:vignetteTomcat5.5webapps">
<filesetdir="..">
<includename="*.war"/>
</fileset>
</copy>
</target>
-->

<!-- Asummarytargetusefulfortestingrecentchangeswithoutupdating
sourcecontrol.Deploystheexpandedversionofthewebarchive.
-->
<!--
<targetname="expanded"depends="compile,test,archive,deploytoTomcat"/>
-->

<!-- incrementisaplaceholderforasource-controlspecificwayofincrementing
thebuildversionofafile,suchasmanifest.mforcomponent.xml.
-->
< target name ="increment" description ="incrementsthebuildartifact" >
< echo message ="Supplyyourincrementlogichere." />
</ target >

<!-- label_and_getisaplaceholderforasource-controlspecificwayoflabeling
thetipandthengettingthatlabel,sothatthescriptwillbuildan
identifiableversionoftheportlet.
-->
< target name ="label_and_get" description ="labelssourcecontroltipandgetsfromthatlabel" >
< echo message ="Supplyyourlabel_and_getlogichere." />
</ target >


<!-- testisaplaceholderforathejunittask. -->
< target name ="test" description ="runsunittests" >
< echo message ="Supplyyourjunittaskhere." />
</ target >

<!-- configuremakessureweb.xmlisproperlyconfiguredforuseonVAP. -->
< target name ="configure" description ="configuresweb.xmlforuseonVAP" >
< PortletPackageTool dir ="../web-root/" contextroot ="${portlet.context.root}" rename ="false" failonerror ="true" />
</ target >


<!-- checkinisaplaceholderforasource-controlspecifictargetthataddsthe
newportletversiontosourcecontrol.
-->
< target name ="checkin" description ="checksthefinal.warintosourcecontrol" >
< echo message ="Supplyyoursourcecontrolcheck-inlogichere." />
</ target >

</ project >

dailybuild.properties:

cvs.root=:pserver:yourcvsaccount:[email protected]:/external/Repo3
cvs.local.root=C:/CVS_HOME

cvs.fs.module=SP_FS
cvs.fw.module=SP_FW
cvs.sportal.module=SPORTAL

bea.home=C:/bea
weblogic.version=8.1
weblogic.username=vigadmin
weblogic.password=vignette
weblogic.domain=vigdomain
weblogic.adminservername=adminserver
weblogic.machine=pigalle
weblogic.adminurl=t3://localhost:7001
deploy.servername=vigcluster

java.classpath=C:/bea/jdk142_11/lib

vignette.server.path=C:/Vignette/Portal

infoboard.remote.server=C:/SPUpload
portlet.warfile.name=Infoboard.war
portlet.app.name=Service_Portal_Infoboard_Application

ui.remote.dir=C:/Vignette/Portal/deployment/upload
uim.carfile.name=uim.car
spui.carfile.name=ServicePortalUI.car

代码分析:

< target name ="check-out-fs" >
< delete dir ="${fs.module.name}" />
< cvs cvsRoot ="${cvsroot}" package ="${fs.module.name}" command ="checkout${fs.module.name}" />
</ target >

Check out cvs,你必须首先安装cvs client,包括wincvs和cvsnt.安装完cvs候需要重启计算机,然后进入cmd.键入cvs,如果安装成功会提示cvs的版本等一些信息.

cvsRoot 是用于鉴别用户访问权限和路径的.一般写在properties里面,package是你要check out 的Module.command支持cvs命令.such as update delete等..

< taskdef name ="wldeploy" classname ="weblogic.ant.taskdefs.management.WLDeploy" >
< classpath location ="${weblogic.lib}/weblogic.jar" />
</ taskdef >

定义了weblogic deployer类的位置,我们在deploy to weblogic的时候使用的就是Deployer的类.这里将其引入,下面的代码就能够使用wldeploy这个标签了.

< target name ="deploywartoServer" description ="Deploytoweblogic" >
< echo message ="Deployed${portlet.warfile.name}toWeblogicAppServer" />
< wldeploy action ="deploy" source ="${infoboard.remote.server}/${portlet.warfile.name}" name ="${portlet.app.name}" debug ="true" targets ="${deploy.servername}" adminurl ="${weblogic.adminurl}" user ="${weblogic.username}" password ="${weblogic.password}" />
</ target >

antion通常有:deploy redeploy start stop等.

source:你需要部署的war包的位置

name:war包的名称

targets:部署应用的目标服务器(cluster or nodemanager)

adminurl:default is t3://localhost:7001

username:your weblogic admin user name

password:your weblogic admin password.

< target name ="reboot-server" description ="Startsamanagedserver" >
<!-- NeedtoinvokelookupNodeManagerRuntimebeforewecanlookuptheruntimembean -->
< java classname ="weblogic.Admin" failonerror ="false" fork ="true" classpathref ="weblogic.classpath" >
< arg line ="-url${weblogic.adminurl}" />
< arg line ="-username${weblogic.username}" />
< arg line ="-password${weblogic.password}" />
< arg line ="INVOKE" />
< arg line ="-mbean${weblogic.domain}:Name=${weblogic.machine},Type=Machine" />
< arg line ="-methodlookupNodeManagerRuntime" />
</ java >

< java classname ="weblogic.Admin" failonerror ="false" fork ="true" classpathref ="weblogic.classpath" >
< arg line ="-url${weblogic.adminurl}" />
< arg line ="-username${weblogic.username}" />
< arg line ="-password${weblogic.password}" />
< arg line ="-mbean${weblogic.domain}:Location=${weblogic.adminservername},Name=${weblogic.machine},ServerRuntime=${weblogic.adminservername},Type=NodeManagerRuntime" />
< arg line ="stopcluster-clusternamevigcluster" />
</ java >

<!-- LookuptheNodeManagerRuntimeMBeanandgivethecommandtostartit. -->
< java classname ="weblogic.Admin" failonerror ="false" fork ="true" classpathref ="weblogic.classpath" >
< arg line ="-url${weblogic.adminurl}" />
< arg line ="-username${weblogic.username}" />
< arg line ="-password${weblogic.password}" />
< arg line ="-mbean${weblogic.domain}:Location=${weblogic.adminservername},Name=${weblogic.machine},ServerRuntime=${weblogic.adminservername},Type=NodeManagerRuntime" />
< arg line ="startcluster-clusternamevigcluster" />
</ java >
</ target >

重启服务器:这里重启的是cluster下面的基于nodemanager管理的服务器.

重启这个服务器需要在weblogic里面配置Machine.

Log in to the weblogic console.点击左边Machines 然后create 自己的machine,nodemanager的选项默认,然后把你要托管的管理服务器选上,重启weblogic.(不要选择adminserver).

关于重启非nodemanager的服务器(代码如下)

< target name ="start-server" depends ="stop-server" >
< java classname ="weblogic.Server" fork ="yes" classpathref ="weblogic.classpath" failonerror ="true" >
< sysproperty key ="weblogic.Domain" value ="${weblogic.domain}" >
</ sysproperty >
< sysproperty key ="weblogic.NodeManager" value ="${weblogic.home}/commom/nodemanager" >
</ sysproperty >
< sysproperty key ="weblogic.RootDirectory" value ="${weblogic.config.dir}" >
</ sysproperty >
< sysproperty key ="weblogic.ConfigFile" value ="${weblogic.config.name}" >
</ sysproperty >
< sysproperty key ="weblogic.ListenPort" value ="7003" >
</ sysproperty >
< sysproperty key ="weblogic.ListenAddress" value ="" >
</ sysproperty >
< sysproperty key ="weblogic.management.server" value ="${weblogic.adminurl}" >
</ sysproperty >
< sysproperty key ="java.security.policy" value ="${weblogic.home}/server/lib/weblogic.policy" >
</ sysproperty >
< sysproperty key ="weblogic.Name" value ="${weblogic.servername}" >
</ sysproperty >
< arg line ="-ms32m-mx200m" >
</ arg >
< arg line ="-Xnohup" >
</ arg >
< jvmarg value ="-Dcom.vignette.portal.installdir.path=C:VignettePortal" />
</ java >
</ target >

你可能感兴趣的:(Build)