wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.reporpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.keyyum install jenkinsyum install javayum install java-1.6.0-openjdkyum install phpyum install php-develyum install php-pearyum install re2cyum install php-pecl-imagickyum install php-domyum install php-pear-phingyum install php-phpunit-PHPUnityum install php-phpunit-phpcpdpear channel-discover pear.phpmd.orgpear install --alldeps phpmd/PHP_PMD
service jenkins startchkconfig jenkins on
Role Strategy(基于角色的权限管理)Publish Over SSH Plugin(通过ssh发布代码)Phing(php构建工具)PMD(代码静态检查)PlotJDependDRY
基于角色的权限管理使用Role Strategy插件实现权限管理,设置在:系统管理-->Manage and Assign Roles
通过ssh发布代码(免密码输入)通过项目前缀+正则匹配,可实现项目组的权限管理
useradd jenkins_publisher
keygen -t rsa (全部选择是)然后在 /root/.ssh/ 能够找到公私钥
1.将 发布机上的 /root/.ssh/id_rsa.pub 传送到 生产机的 /home/jenkins_publisher/.ssh/2.将 id_rsa.pub 改名为 authorized_keys3.将 authorized_keys 设置为 jenkins_publisher 所有
【首次部署】创建对应的 程序包目录: mkdir -p /data/svn_data/chown -R jenkins_publisher /data/svn_data/(根据实际部署环境)【每次应用部署】创建对应的 web程序目录: mkdir -p /data/www/*** (根据实际部署环境)更改目录的所有者: chown -R jenkins_publisher /data/www/***
发布到生产机
在程序svn根目录添加 build.xml 文件
<?xml version="1.0" encoding="UTF-8"?> <project name="ceshi" default="build"> <target name="build" depends="make_runtime,pdepend,phpmd,phpcpd,test,check,tar"/> <property name="version-m" value="1.1" /> <property name="version" value="1.1.0" /> <property name="stability" value="stable" /> <property name="releasenotes" value="" /> <property name="tarfile" value="${phing.project.name}.${buildnumber}.${buildid}.tar.gz" /> <property name="pkgfile" value="${phing.project.name}.${version}.tgz" /> <property name="distfile" value="dist/${tarfile}" /> <property name="tests.dir" value="tests" /> ####程序的目录(根据实际情况更改) <fileset id="ceshi.tar.gz" dir="."> <include name="tests/**"/> <include name="assets/**"/> <include name="js/**"/> <include name="css/**"/> <include name="images/**"/> <include name="protected/**"/> <include name="*.php"/> </fileset> ####集成构建相关配置 <target name="make_runtime"> <mkdir dir="${project.basedir}/Runtime" /> <mkdir dir="${project.basedir}/build/logs" /> <mkdir dir="${project.basedir}/build/pdepend" /> <mkdir dir="${project.basedir}/build/code-browser" /> </target> ####php代码规模分析工具配置 <target name="pdepend" description="Calculate software metrics using PHP_Depend"> <exec executable="pdepend"> <arg value="--jdepend-xml=${project.basedir}/build/logs/jdepend.xml"/> <arg value="--jdepend-chart=${project.basedir}/build/pdepend/dependencies.svg"/> <arg value="--overview-pyramid=${project.basedir}/build/pdepend/overview-pyramid.svg"/> <arg path="${project.basedir}/"/> </exec> </target> ####php代码静态检查工具配置 <target name="phpmd" description="Perform project mess detection using PHPMD"> <phpmd> <fileset dir="${project.basedir}"> <include name="protected/*.php" /> <include name="*.php" /> </fileset> </phpmd> </target> ####php代码分析工具配置 <target name="phpcpd" description="Find duplicate code using PHPCPD"> <phpcpd> <fileset dir="${project.basedir}"> <include name="*.php" /> </fileset> <formatter type="pmd" outfile="pmd-cpd.xml"/> </phpcpd> </target> ####php单例测试配置 <target name="test" description="Run PHPUnit tests"> <phpunit haltonerror="true" haltonfailure="true" printsummary="true"> <batchtest> <fileset dir="${tests.dir}"> <include name="**/*Test.php" /> </fileset> </batchtest> </phpunit> </target> ####构建参数配置 <target name="check" description="Check variables" > <fail unless="version" message="Version not defined!" /> <fail unless="buildnumber" message="buildnumber not defined!" /> <fail unless="buildid" message="buildid not defined!" /> <delete dir="dist" failonerror="false" /> <mkdir dir="dist" /> </target> ####构建参数配置 <target name="tar" depends="check" description="Create tar file for release"> <echo msg="Creating distribution tar for ${phing.project.name} ${version}"/> <delete file="${distfile}" failonerror="false"/> <tar destfile="${distfile}" compression="gzip"> <fileset refid="ceshi.tar.gz"/> </tar> </target> </project>jenkins 打包代码配置
打包配置
配置jenkins 的ssh发布(可执行shell)
发布目录配置
代码发布
构建结果
整理于2015/02