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

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

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


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

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

注意要填写user name和 email地址,否则日后会碰到git tag的错误


2.在Jenkins使用的机器上创建Git用户所需要的公钥

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

http://blog.youkuaiyun.com/sheismylife/article/details/7204345

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


3.修改jenkins目录权限

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.youkuaiyun.com/sheismylife/article/details/7209722

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

首先清空里面所有的jar包,然后创建settings.xml文件,并编辑内容如下:

<settings> <mirrors> <mirror> <!--This sends everything else to /public --> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://S1:8081/nexus/content/groups/public</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <!--Enable snapshots for the built in central repo to direct --> <!--all requests to nexus via the mirror --> <repositories> <repository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <!--make the profile active all the time --> <activeProfile>nexus</activeProfile> </activeProfiles> </settings>
现在点击build now测试一下,打开console output,看看命令行输出结果,如果发现从S1下载jar包,就正确。和不用私服的比较了一下,节省了1分多钟.






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值