1. 程式人生 > 其它 >jenkins建立構建任務

jenkins建立構建任務

jenkins建立構建任務

環境:linux

jenkins:Jenkins 2.332.3

jdk:jdk-11.0.15

一、部署

略,參考官網

二、建立構建任務

1、安裝初始化後,根據需求安裝外掛。

2、新建任務

 本次構建一個自由風格的軟體專案,這個更好入門,配置起來對比好理解。

 3、下面將已配置好的一個任務相關配置地方展示如下:

整體一個流程:

1、從版本庫svn上下載原始碼;

2、通過ant編譯,難點build.xml 的編寫;說明:ant的版本是自行安裝的,jenkins初始化的版本太高了。

3、通過ssh上傳待更新主機,根據實際情況處理。

 此處要想使用send files or execute commands over SSH的話,需在自行在外掛中安裝

 本次環境有些特殊,應用更新是增量,編譯後通過更新列表檔案(OnlineDate.txt)提取增量更新檔案。

ant  build.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="exec" name="test">
        <property environment="env"/>
            <target name="init" description="">
            <
property name="name" value="test"/> <property name="src" value="${basedir}/src"/> <property name="lib" value="${basedir}/WebRoot/WEB-INF/lib"/> <property name="webapp" value="${basedir}/WebRoot"/> <property name="resource" value="${basedir}/src/resources"
/> <property name="build.encoding" value="UTF-8" /> <property name="build.src" value="${basedir}/build/src"/> <property name="build.classes" value="${basedir}/build/classes"/> <property name="build.webapp" value="${basedir}/build/webapp"/> <property name="build.javadocs" value="${basedir}/build/doc"/> <property name="jar.dest" value="${basedir}/build/jar"/> <property name="war.dest" value="${basedir}/build/war"/> <property name="tomcat.home" value="/apache-tomcat-7.0.104"/> <property name="jdk.home" value="/jdk/jdk1.7.0_161"/> <property name="env" value="test"/> <path id="classpath"> <fileset dir="${lib}"> <include name="**/*.jar"/> </fileset> <fileset dir="${tomcat.home}/lib"> <include name="**/*.jar"/> </fileset> <fileset dir="${jdk.home}/lib"> <include name="**/*.jar"/> </fileset> </path> </target> <target name="prepare" depends="init" description="建立打包需要的路徑,拷貝原始檔到打包路徑下"> <echo>mkdir base start</echo> <mkdir dir="${build.src}"/> <mkdir dir="${build.classes}"/> <mkdir dir="${build.webapp}"/> <mkdir dir="${jar.dest}"/> <mkdir dir="${war.dest}"/> <echo>copy ${basedir} start</echo> <copy todir="${build.src}"> <fileset dir="${src}"/> </copy> <copy todir="${build.classes}"> <fileset dir="${resource}"/> </copy> <copy todir="${build.webapp}"> <fileset dir="${webapp}"/> </copy> </target> <target name="build" depends="prepare" description="編譯 java 檔案,拷貝 properties 屬性配置檔案到編譯後的路徑下"> <echo message="開始編譯" /> <javac srcdir="${build.src}" destdir="${build.classes}" executable="${jdk.home}/bin/javac" includeantruntime="false" encoding="${build.encoding}" target="1.7" source="1.7" > <classpath refid="classpath"/> </javac> </target> <target name="addconfig" depends="build" description="加入非resource下的prop和xml檔案"> <copy todir="${build.classes}"> <fileset dir="${src}/main"> <include name="**/*.xml"/> <include name="**/*.properties"/> </fileset> </copy> </target> <target name="antwar" depends="addconfig" description="打 war 包,不將 java 檔案打入包內"> <delete dir="${build.src}"/> <war warfile="${war.dest}/${name}.war" webxml="${build.webapp}/WEB-INF/web.xml"> <lib dir="${build.webapp}/WEB-INF/lib"/> <classes dir="${build.classes}"/> <fileset dir="${build.webapp}"/> </war> </target> <target name="exec" depends="clean,antwar" description="打包編譯開始,並清除war包"> </target> <target name="clean" depends="init" description="清除打包用臨時檔案"> <echo message="清理war包"></echo> <delete dir="${war.dest}"/> <delete dir="${build.classes}"/> <delete dir="${build.webapp}"/> </target> </project>

update_file.sh 內容及待更新檔案列表

#!/bin/bash
#
appname='test'

if [ -z $appname ]; then
    echo "---appliction name null!!!---"
    exit 1
fi

sourcepath="/temp"
targetpath="/$appname"
onlinefile="$1"
dos2unix $onlinefile
onlinepath=${onlinefile%%.*}

#clear history file
if [ -d $sourcepath/$appname/WebRoot ];then
    rm -rf $sourcepath/$appname/WebRoot
fi

if [ -d $sourcepath/$appname/$onlinepath ];then
    rm -rf $sourcepath/$appname/$onlinepath
fi


#create update path
if [ ! -d $sourcepath/$appname/$onlinepath ];then
    mkdir $sourcepath/$appname/$onlinepath
fi

sed -i 's#.java$#*.class#g' $sourcepath/$appname/$onlinefile
sed -i 's#^src/main#WebRoot/WEB-INF/classes#g' $sourcepath/$appname/$onlinefile
sed -i 's#^src/resources#WebRoot/WEB-INF/classes#g' $sourcepath/$appname/$onlinefile

unzip -o -q  $sourcepath/$appname/$appname.war -d $sourcepath/$appname/WebRoot

for file in `grep -v "^#" $sourcepath/$appname/$onlinefile`
do
    echo $file
    #update file
    if [ ! -d $sourcepath/$appname/$onlinepath/${file%/*} ];then
        mkdir -p $sourcepath/$appname/$onlinepath/${file%/*} && \cp -a  $sourcepath/$appname/$file $sourcepath/$appname/$onlinepath/${file%/*}/
    else
        \cp -a  $sourcepath/$appname/$file $sourcepath/$appname/$onlinepath/${file%/*}/
    fi
done

#update application
\cp -a $sourcepath/$appname/$onlinepath/* $targetpath/
sh /${appname}/app_${appname}_server restart

 20220519.txt

# 展示功能
WebRoot/ultra/runtime/theme/responsive/css/layout-fix.css
WebRoot/ultra/runtime/theme/responsive/form.jsp
WebRoot/WEB-INF/classes/runtime/manage/ProcessManagerImpl.java