持续集成(C I)工具Jenkins入门

这几天研究了一下持续集成(CI)工具Jenkins,感觉很强大,入门也很简单,今天就写一个入门的小例子,对于一般性的小项目足够用了,如果大家用到了更复杂的相信学会这篇文章之后,也一定能自己搞定了 安装 Jenkins是Java开发的,我们只需要到他的官网:http://jenkins-ci.org下载一个war包,扔到servlet容器(例如:tomcat)中,启动就可以了,和普通的war启动没什么差别,如果你还不会,那么你需要补J2EE的基础了。 安装插件 启动完成之后,是这样的, Jenkins自己已经帮我们安装了好多很好用的插件,但有些还是要我们自己装,例如:Git Client Plugin、Git Plugin,要安装这些,我们只需要点击左边的“系统管理” –> 管理插件 –> 可选插件,找到这两个插件装上就好了,装好插件下一步就是配置了 配置 配置,同样“系统管理” –> 系统设置,下面开始配置: ①. Maven Configuration配置 就是maven的settings文件的位置 ②. JDK配置 新增JDK,然后大家一看就应该懂了,尽量不要自动安装 ③. Git 也一样,就是Git的路径,需要注意的是:Git的路径一直要到bin下面的exe文件(Linux还没用过,所以不清楚,但我相信大家都懂得了) ④. Maven配置 这个和JDK的配置是一样的 ⑤. Maven项目配置 Maven仓库的地址,我选的是第三个Local to the workspace,其实无所谓 ⑥. Jenkins URL 就改成127.0.0.1吧,或者其他合适的,邮件地址就写自己的啦 ⑦. Git plugin 这个相信不用多说了,Git我们都配过 这些目前是必须的配置,其他的大家就根据需要或者自己的理解,要么不配也行 需要说明的是,我没有配ant,用到了可以自己配一下,一样的,配置完成后选择“保存”就好了 新建一个任务 这个大家都能找到在哪,然后进入到 填入Item名称,选择构建一个maven项目,点击“OK”到下一页,需要说明的: ①. 源码管理,这个也是最重要的,我选的是Git,这也是在一开始我安装那两个插件的原因,如果不安装那两个插件,是不会有Git这个选项的,然后键入要构建的项目的URL,点击“Add”,添加用户名和密码,切记一定要这么选择 其中Username是默认的,可以改,但Kind和Private Key强烈建议和我选的一样,否则可能会报代码拉不下来的错误,反正我是被这个错浪费了一天,然后这么选之后就对了,所以建议大家这么干,当然也可以自己选择其他的,大家可以试试。 ②. 构建触发器 Poll SCM、Build periodically这个是我们配置定时任务,也就是定时自动构建项目的,他们的区别: Poll SCM:定时检查源码变更(根据SCM软件的版本号),如果有更新就checkout最新code下来,然后执行构建动作。我的配置如下: \*/5 \* \* \* * (每5分钟检查一次源码变化) Build periodically:周期进行项目构建(它不care源码是否发生变化),我的配置如下: ...

May 24, 2015 · 1 min · 130 words · Bridge Li

ANT(build)脚本模板示例

近来虽然Maven构建的项目越来越盛行,但是依然还有很多遗留(暂且称之为遗留吧)项目依然是由ANT编译的,今天老夫就整理一下自己目前公司项目用到的ANT模板,既作为老夫的学习笔记,以供将来查看,也分享出来供需要的参考,因为比较简单易懂,就不多说了,直接上代码 <?xml version="1.0" encoding="UTF-8"?> <!&#8211; Ant工程build模板 ant build file Example: ant -Dprofile=dev deploy test IDC测试环境 dev 本地开发环境 (default) &#8211;> <project name="antProject" basedir="." default="prompt"> <property name="javac.version" value="1.6" /> <property name="project.name" value="projectname" /> <property name="source.encoding" value="UTF-8" /> <property name="deploy.dir" value="/tmp/${project.name}" /> <!&#8211; project var set &#8211;> <property name="target.path" value="build" /> <property name="target.root.path" value="${target.path}/ROOT" /> <property name="target.root.classes" value="${target.root.path}/WEB-INF/classes" /> <property name="webroot.path" value="WebRoot" /> <property name="compileSrc" value="src" /> <property name="compileDest" value="${target.root.classes}" /> <property name="env.dir" value="env" /> <property name="env.cfg" value="${env.dir}/${profile}" /> <tstamp> <format property="now" pattern="yyyyMMddHHmmss" /> </tstamp> <path id="compileClassPath"> <fileset dir="${webroot.path}/WEB-INF/lib"> <include name="*.jar" /> </fileset> </path> <target name="prompt" description="show prompt information"> <echo>Please choose task: clean, compile, war, deploy. ${line.separator} Example: ${line.separator} ant compile ${line.separator} ant -Dprofile=test deploy </echo> </target> <target name="clean"> <delete dir="${target.path}" /> <mkdir dir="${target.path}" /> <delete dir="${compileDest}" /> <mkdir dir="${compileDest}" /> <delete dir="${target.root.classes}" /> <mkdir dir="${target.root.classes}" /> <echo>cleaned for ${compileDest}, ${target.root.path},${target.path}/*.war</echo> </target> <target name="compile" depends="clean,testIfProfileSet"> <echo>starting compile the source from ${compileSrc}</echo> <javac srcdir="${compileSrc}" includeantruntime="false" fork="true" memoryinitialsize="256m" memorymaximumsize="512m" destdir="${compileDest}" classpathref="compileClassPath" encoding="${source.encoding}" source="${javac.version}" target="${javac.version}" debug="true" verbose="false" optimize="true" deprecation="false"> </javac> <copy todir="${compileDest}"> <fileset dir="${compileSrc}" excludes="*\*/\*.svn,*\*/\*.java" /> </copy> <echo>compiled classes copied to ${compileDest}</echo> <copy todir="${target.root.path}"> <fileset dir="${webroot.path}" excludes="*\*/\*.svn,*\*/\*.java" /> </copy> <echo>copied to ${webroot.path} to ${compileDest}</echo> <echo>compile finished</echo> </target> <target name="testIfProfileSet"> <echo>ant param profile: ${profile}</echo> <condition property="isProfileSet"> <!&#8211; <isset property="${profile}" /> &#8211;> <or> <equals arg1="${profile}" arg2="dev" /> <equals arg1="${profile}" arg2="test" /> </or> </condition> <antcall target="profileProvided"> </antcall> <antcall target="noProfile"> </antcall> </target> <target name="profileProvided" if="isProfileSet"> <copy todir="${target.root.classes}"> <fileset dir="${env.cfg}" /> </copy> <echo>copied config files ${env.cfg} to ${target.root.classes}</echo> </target> <target name="noProfile" if="isProfileSet"> <echo>ant param profile is none, use default config files</echo> </target> <target name="war" depends="compile"> <jar jarfile="${target.path}/${project.name}-${profile}${now}.war"> <fileset dir="${target.root.path}"> <include name="*\*/\*" /> <exclude name="*\*/\*.fla" /> <exclude name="*\*/\*.mp3" /> <exclude name="*\*/\*.as" /> <exclude name="*\*/\*.bak" /> <exclude name="*\*/\*.swd" /> <exclude name="*\*/\*.db" /> </fileset> </jar> </target> <target name="deploy" depends="compile"> <delete dir="${deploy.dir}" /> <mkdir dir="${deploy.dir}" /> <copy todir="${deploy.dir}"> <fileset dir="${target.root.path}"> </fileset> </copy> <echo>deploy ${target.root.path} to ${deploy.dir}</echo> </target> </project>

May 10, 2015 · 2 min · 303 words · Bridge Li