Jenkins中使用Git和Maven之基本配置

Jenkins有一些专用术语,请参考下面的链接: html

https://wiki.jenkins-ci.org/display/JENKINS/Terminology git


1.经过Jenkins web页面添加Git plugin web

Manage Jenkins->Manage Plugins->Available中选择Git Plugin安装, app

注意要填写user name和 email地址,不然往后会碰到git tag的错误 ssh


2.在Jenkins使用的机器上建立Git用户所须要的公钥 maven

具体步骤参考前面Git server文章 测试

http://blog.csdn.net/sheismylife/article/details/7204345 ui

可是注意,要将最后生成的.ssh目录下的公钥和私钥文件复制到/var/lib/jenkins/.ssh目录下,不然git clone命令会报错 url


3.修改jenkins目录权限 spa

chmod -R 777 /var/lib/jenkins


4.如今能够经过web页面建立一个项目Test,而后设置该项目使用Git做为版本管理。

而且设置repository路径,好比个人:git@S1 :cml.git


5.在build选项的pom文件指定你须要执行的pom.xml路径

好比个人一个测试工程名叫client,是个maven工程,我设置为client/pom.xml


6.如今能够点击左侧的Build now进行测试


一切OK,则没有错误日志。在Build History中能够看到测试结果,有没有错误。


7.Email发送设置

在Manage Jenkins->Configure System->Email Notification中,设置SMTP发送的基本信息,点击Advanced,能够填写用户名和密码。还有一个测试按钮能够用来发送测试设置是否正确。


同时在Test项目中的Building Settings打勾选中E-mail Notification,点击右边的问号,会出现帮助文档,说明在四种状况下会发送email,填写接受email的地址,而后故意将client代码修改到不能编译经过。而后点击Build now按钮测试一下。果真收到email.


8.检查代码更新并编译

能够经过Poll SCM来设置定时检查编译功能

好比*/5 * * * * 就是每隔5分钟检查一次,若是git仓库中有更新,则执行build操做。


9.使用Maven私服加快下载速度

如我这篇文章所述,用私服能够避免下载过慢问题,也能够绕过公司内部外网限制问题。

http://blog.csdn.net/sheismylife/article/details/7209722

Jenkins的.m2目录路径在:/var/lib/jenkins/.m2/

首先清空里面全部的jar包,而后建立settings.xml文件,并编辑内容以下:

[html]  view plain copy print ?
  1. <settings>  
  2.   <mirrors>  
  3.     <mirror>  
  4.       <!--This sends everything else to /public -->  
  5.       <id>nexus</id>  
  6.       <mirrorOf>*</mirrorOf>  
  7.       <url>http://S1:8081/nexus/content/groups/public</url>  
  8.     </mirror>  
  9.   </mirrors>  
  10.   <profiles>  
  11.     <profile>  
  12.       <id>nexus</id>  
  13.       <!--Enable snapshots for the built in central repo to direct -->  
  14.       <!--all requests to nexus via the mirror -->  
  15.       <repositories>  
  16.         <repository>  
  17.           <id>central</id>  
  18.           <url>http://central</url>  
  19.           <releases><enabled>true</enabled></releases>  
  20.           <snapshots><enabled>true</enabled></snapshots>  
  21.         </repository>  
  22.       </repositories>  
  23.       <pluginRepositories>  
  24.         <pluginRepository>  
  25.           <id>central</id>  
  26.           <url>http://central</url>  
  27.           <releases><enabled>true</enabled></releases>  
  28.           <snapshots><enabled>true</enabled></snapshots>  
  29.         </pluginRepository>  
  30.       </pluginRepositories>  
  31.     </profile>  
  32.   </profiles>  
  33.   <activeProfiles>  
  34.     <!--make the profile active all the time -->  
  35.     <activeProfile>nexus</activeProfile>  
  36.   </activeProfiles>  
  37. </settings>  

如今点击build now测试一下,打开console output,看看命令行输出结果,若是发现从S1下载jar包,就正确。和不用私服的比较了一下,节省了1分多钟.
相关文章
相关标签/搜索