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

 

posted on 2022-05-19 17:51  浊酒三杯  阅读(1221)  评论(0编辑  收藏  举报