devops流水线-ant打包
流水线设置
编辑 build.sh 文件
# 脚本目录为代码库根目录
# sh ./build.sh
# 下载jdt包(使用eclipse的方式编译)
mkdir jdt
cd jdt/
wget -O "eclipse-jdt.tar" "http://devops.手动上传jdt包到半成品库里." --no-check-certificate
tar -xvf eclipse-jdt.tar
# 把jdt包复制到ant的依赖库里
cp *.jar /opt/apache-ant-1.9.16/1ib
cd ..
echo "#!/bin/bash
## gbk转成utf8 iconv -f gbk -t utf-8 Xxx.java > Xxx1.java
gbk_to_utf8()
{
##判断gbk.txt是否存在
if [ -e ./gbk.txt ]; then
for item in \`cat ./gbk.txt\`
do
echo \$item
iconv -f gbk -t utf-8 \$item >\$item\"1\"
usleep 200
rm \$item
usleep 150
mv \$item\"1\" \$item
done
fi
}
## 递归查找gbk编码的文件,并把文件名写入到gbk.txt
read_dir()
{
for file in \`1s \$1\`
do
if [ -d \$1/\$file ]; then
read_dir \$1/\$file
elif [[ \"\$file\" = *.java ]]; then
echo \$1/\$file
file -b \$1/\$file|grep \"ISO-8859\"
if [ \$? -eq 0 ]; then
echo \$1/\$file >> gbk.txt
fi
fi
done
}
echo \"将gbk源码写入到gbk.txt ...\"
read_dir \`pwd\`
gbk_to_utf8
"> gbk_to_utf8.sh
chmod 775 gbk to utf8.sh
# ./gbk_to_utf8.sh
# cat gbk.txt
echo "赋予权限"
chmod 777 build-war.xml
echo "修改build-war.xml"
# cp -rf $(pwd) /WebRoot/WEB-INF/comp/platform/* $(pwd)/WebRoot/WEB-INF/lib
# 使用测试环境的配置
cat $(pwd)/WebRoot/WEB-INF/config/platform/commonCfg_uat.properties> $(pwd)/WebRoot/WEB-INF/config/platform/commonCfg.properties
sed -i 's/116/103/' sra-jstl/db.properties
# 增量打包放开以下脚本
# echo "获取["${oldCommitID}"]-["${newCommitID}"]的差异,生成diff.txt ..."
# git diff ${oldCommitID} ${newCommitID}--name-only--diff-filter=AM > diff.txt
# echo "cat diff.txt"
# cat diff.txt
# 关闭强制中文转译
# git config --global core.quotepath off
echo "开始ant..."
ant -f build-war.xml
# echo "打包文件"
tar -zevf scf.tar scf.war diff.txt
echo "finish..."
编辑 build-war.xml 文件
<?xml version="1.0" encoding="GBK"?>
<project basedir="." default="war" name="scf">
<!-- ant 编译日志 -->
<record name="ant.log" loglevel="info" append="no" action="start"/>
<property name="sourcePath" value="."/>
<property name="deployTomcat.dir" value="."/>
<property name="findbugs.home" value="${basedir}/p3th_antlib/findbugs-3.0.1" />
<property name="deployPath" value="${deployTomcat.dir}/WebRoot"/>
<property name="sourcePath.root" value="${sourcePath}/WebRoot"/>
<property name="webapp.root.classes" value="${deployPath}/WEB-INF/classes"/>
<property name="webapp.dir.classes" value="${deployPath}/WEB-INF/comp/platclasses"/>
<property name="lib.dir" location="${sourcePath.root}/WEB-INF/lib"/>
<property name="comp.lib.dir" location="${sourcePath.root}/WEB-INF/comp/platform" />
<!-- path to the svnant libraries. Usually they will be located in ANT HOME/lib -->
<path id="p3th.antlib">
<fileset dir="${basedir}/p3th_antlib">
<include name="**/*.jar"/>
</fileset>
</path>
<!-- 编译依赖的lib jar -->
<path id="depend libs">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
<fileset dir="${comp.lib.dir}" includes="**/*.jar"/>
<pathelement location="${webapp.root.classes}"/>
<pathelement location="${webapp.dir.classes}"/>
</path>
<!-- 清理class文件 -->
<target name="clean">
<delete file="scf.war"/>
<delete dir="${webapp.root.classes}"/>
<delete dir="${webapp.dir.classes}"/>
<mkdir dir="${webapp.root.classes}"/>
<mkdir dir="${webapp.dir.classes}"/>
</target>
<!-- 编译 -->
<target name="compile" depends="clean">
<!-- compiler的JDT为了生成的class与eclipse本地编译打包生成的一致 -->
<javac srcdir="S{basedir}" encoding="GBK" destdir="${webapp.dir.classes}"includeAntRuntime="false" debug="true" debuglevel="vars,lines,source" compiler="org.eclipse.jdt.core.JDTCompilerAdapter" target="1.7" source="1.7" fork="true" optimize="false">
<compilerarg value="-xDignore.symbol.file"/>
<compilerarg value="-preserveAllLocals"/>
<compilerarg value="-nowarn"/>
<compilerarg value="-xlint:-unchecked"/>
<classpath refid="depend libs"></classpath>
</javac>
<!-- 以下的copy与move是为了让流水线ant打包后的文件位置与使用流水线之前eclipse本地打包的一致 -->
<delete dir="${webapp.dir.classes}/src-intf"/>
<copy overwrite="true" todir="${webapp.dir.classes}" verbose="true">
<fileset dir="src-data-auth" includes="**/*.sql"/>
</copy>
<copy overwrite="true" todir="${webapp.dir.classes}/META-INF" verbose="true">
<fileset dir="src-accounting/META-INF"/>
<fileset dir="src-accval/META-INF"/>
<fileset dir="src-carfinance/META-INF"/>
<fileset dir="src-cprsv/META-INF"/>
<fileset dir="src-ctfn/META-INF"/>
<fileset dir="src-customer/META-INF"/>
<fileset dir="src-data-auth/META-INF"/>
<fileset dir="src-disbursement/META-INF"/>
<fileset dir="src-draft/META-INF"/>
<fileset dir="src-intf/META-INF"/>
<fileset dir="src-inventory/META-INF"/>
<fileset dir="src-limit/META-INF"/>
<fileset dir="src-network/META-INF"/>
<fileset dir="src-order/META-INF"/>
<fileset dir="src-yl/META-INF"/>
</copy>
<copy overwrite="true" todir="${webapp.root.classes}" verbose="true">
<fileset dir="src-jstl">
<include name="**/*.*"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
<copy overwrite="true" todir="${deployPath}/jspRoot/accounting/" verbose="true">
<fileset dir="src-accounting/META-INF/jsp" includes="**/*.jsp"/>
</copy>
<copy overwrite="true" todir="${deployPath}/jspRoot/accval/" verbose="true">
<fileset dir="src-accval/META-INF/jsp" includes="**/*.jsp"/>
</copy>
<copy overwrite="true" todir="${deployPath}/jspRoot/sra-carfinance/" verbose="true">
<fileset dir="src-carfinance/META-INF/jsp" includes="**/*.jsp" />
</copy>
<copy overwrite="true" todir="${deployPath}/jspRoot/src-cprsv/" verbose="true">
<fileset dir="src-cprsv/META-INF/jsp" includes="**/*.jsp"/>
</copy>
<copy overwrite="true" todir="${deployPath}/jspRoot/sra-ctfn/" verbose="true">
<fileset dir="src-ctfn/META-INF/jsp" includes="**/*.jsp"/>
</copy>
<copy overwrite="true" todir="${deployPath}/jspRoot/sra-customer/" verbose="true">
<fileset dir="src-customer/META-INF/jsp" includes="**/*.jsp"/>
</copy>
<copy overwrite="true" todir="${deployPath}/jspRoot/src-disbursement/" verbose="true">
<fileset dir="src-disbursement/META-INF/jsp" includes="**/*.jsp"/>
</copy>
<copy overwrite="true" todir="${deployPath}/jspRoot/src-draft/" verbose="true">
<fileset dir="src-draft/META-INF/jsp" includes="**/*.jsp"/>
</copy>
<copy overwrite="true" todir="${deployPath}/jspRoot/inventory/" verbose="true">
<fileset dir="src-inventory/META-INF/jsp" includes="**/*.jsp"/>
</copy>
<copy overwrite="true" todir="${deployPath}/jspRoot/src-limit/" verbose="true">
<fileset dir="src-limit/META-INF/jsp" includes="**/*.jsp"/>
</copy>
<copy overwrite="true" todir="${deployPath}/jspRoot/sra-network/" verbose="true">
<fileset dir="sra-network/META-INF/jsp" includes="**/*.jsp"/>
</copy>
<copy overwrite="true" todir="${deployPath}/jspRoot/src-order/" verbose="true">
<fileset dir="src-order/META-INF/jsp"lincludes="**/*.jsp"/>
</copy>
<copy overwrite="true" todir="${deployPath}/jspRoot/system/" verbose="true">
<fileset dir="src-system/META-INF/jsp" includes="**/*.jsp"/>
</copy>
<move overwrite="true" todir="${webapp.root.classes}/com/tansun/workflow/" verbose="true">
<fileset dir="${webapp.dir.classes}/com/tansun/workflow" includes="**/*.class"/>
</move>
<move overwrite="true" todir="${webapp.root.classes}/com/tansun/scf/filter/" verbose="true">
<fileset dir="${webapp.dir.classes}/com/tansun/scf/filter" includes="**/*.class"/>
</move>
<move overwrite="true" todir="${webapp.root.classes}/com/tansun/scf/ireport/" verbose="true">
<fileset dir="${webapp.dir.classes}/com/tansun/scf/ireport" includes="**/*.class"/>
</move>
<move overwrite="true" todir="${webapp.root.classes}/com/tansun/scf/quartz/" verbose="true">
<fileset dir="${webapp.dir.classes}/com/tansun/scf/quartz" includes="**/*.class"/>
</move>
<move overwrite="true" todir="${webapp.root.classes}/com/tansun/scf/security/" verbose="true">
<fileset dir="${webapp.dir.classes}/com/tansun/scf/security" includes="**/*.class"/>
</move>
<move overwrite="true" todir="${webapp.root.classes}/com/tansun/scf/servlet" verbose="true">
<fileset dir="${webapp.dir.classes}/com/tansun/scf/servlet" includes="**/*.class"/>
</move>
<move overwrite="true" todir="${webapp.root.classes}/com/tansun/scf/tlds" verbose="true">
<fileset dir="${webapp.dir.classes}/com/tansun/scf/tlds" includes="**/*.class"/>
</move>
<move overwrite="true" todir="${webapp.root.classes}/com/tansun/scf/web" verbose="true">
<fileset dir="${webapp.dir.classes}/com/tansun/scf/web" includes="**/*.class"/>
</move>
<move overwrite="true" todir="${webapp.root.classes}/com/bamboocloud" verbose="true">
<fileset dir="${webapp.dir.classes}/com/bamboocloud" includes="**/*.class"/>
</move>
<move overwrite="true" todir="${webapp.root.classes}/com/ec" verbose="true">
<fileset dir="${webapp.dir.classes}/com/ec" includes="**/*.class"/>
</move>
<move overwrite="true" todir="${webapp.root.classes}/org" verbose="true">
<fileset dir="${webapp.dir.classes}/org" includes="**/*.class"/>
</move>
<move file="${webapp.dir.classes}/com/HibernateConfigurationHelper.class" todir="S{webapp.root.classes}/com" />
</target>
<!-- 打war包 -->
<target name="war" depends="compile">
<mkdir dir="${deployPath}/WEB-INF/classes/login/"/>
<copy overwrite="true" todir="${deployPath}/WEB-INF/classes/login/" verbose="true" file="${deployPath}/WEB-INF/config/platform/1ogin/1oginConfig.properties"/>
<war destfile="${basedir}/${ant.project.name}.war" webxml="${dep1oyPath}/WEB-INF/web.xml">
<fileset dir="${deployPath}">
<include name="**/*.*"/>
<exclude name="**/*.zip"/>
<exclude name="**/*.1og"/>
<exclude name="**/*.1og.*"/>
<exclude name="**/1ogs/**"/>
</fileset>
<classes dir="${webapp.root.classes}"/>
</war>
</target>
</project>
附:ant用eclipse方式编译打包
需要eclipse安装路径下plugins目录中的依赖包
org.eclipse.jdt.core_3.7.3.vxxxxx.jar
org.eclipse.jdt.debug.ui_3.6.1.vxxxxx.jar
jdtCompilerAdapter.jar (从org.eclipse.jdt.core.jar中获取)
使用时可手动上传至半制品库中,并复制其wget路径,在build.sh中引用,解压到 ant指定路径即可。