项目开发环境搭建手记(5.Jenkins搭建)

作者:fbysss
QQ:溜酒酒吧酒吧吾散
blog:blog.csdn.net/fbysss
声明:本文由fbysss原创,转载请注明出处

一、下载

下载地址:http://pkg.jenkins-ci.org/redhat/

这里有下载包

注意:

sudo wget -O /etc/yum.repos.d/jenkins.repohttp://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
yum install jenkins

这样的安装步骤也是可以,但是虚拟机下载的速度是很慢的。还是手工download rpm更好。

 二、安装

rpm -ivhjenkins-1.597-1.1.noarch.rpm 

  1:jenkins               ########################################### [100%]
[root@localhost sss]# rpm -ql jenkins
/etc/init.d/jenkins
/etc/logrotate.d/jenkins
/etc/sysconfig/jenkins
/usr/lib/jenkins
/usr/lib/jenkins/jenkins.war
/usr/sbin/rcjenkins
/var/cache/jenkins
/var/lib/jenkins  ---主目录
/var/log/jenkins

三、配置

vi /etc/sysconfig/jenkins,修改端口号

service jenkis

提示是OK,但是ps一下,jenkins进程没有,端口号也没被占用。

cat /var/log/jenkens/jenkens.log

SEVERE: Container startup failed
java.io.IOException: Failed to start Jetty

...

Caused by: java.net.BindException: Address already in use

 

原来是8009端口和被tomcat占用了。

===>/etc/sysconfig/jenkins要修改两个端口:一个8080,一个8009

在这里,我把它们分别修改为8980,8909

同时,也可以从这里看到,rpm包里面,内嵌了Jetty

四、安装插件,支持git

jenkins默认是不支持git的,需要装插件。

系统管理-》插件管理-》可选插件

选中GitLab Plugin之后,点直接安装,进入一个页面,显示相关的plugin正在下载

——注意需要翻墙连google

  • Git Client Plugin
  • Matrix Project Plugin
  • SCM API Plugin
  • Credentials Plugin
  • Git Plugin
  • GitLab Plugin

 

在配置gitlab信息时,有一个api token,对应gitlab用户的account属性中,Private token的值。



但是配置git仓库的时候,一直报错。

只有用http协议,并且把用户名密码都加上如http://user:pass@host:xxxxxx.git,Credentials选none的时候才可以。

 

Failed to connect to repository : Command "git ls-remote -h git@dev.fbysss.com:app-dev/sssApp.gitHEAD" returned status code 128:
stdout: 

stderr: Permission denied, please tryagain. 
Permission denied, please try again. 
Permission denied(publickey,gssapi-keyex,gssapi-with-mic,password). 
fatal: The remote end hung up unexpectedly



最终解决:还是在细节上没有注意

选择SSH Username with private key

直接输入私钥,要完整复制 ~/.ssh/id_isa里面的内容。

使用From a file on Jenkins master不好使

 

构建的时候,发现错误:mvn command not found.

检查一下设置,maven也已经配置了。

原因是:直接在command shell里面输入mvn是不行的。

采用在设置菜单中,增加构建-》Invoke top-level maven targets,选择我们配置的Maven的名称 ,Goals中输入

clean

install

等,是可以的。

记得在高级设置里面,都用默认的设置,里面是要找maven配置文件settings.xml的。

如果要直接输入shell命令,要打完整的路径——因为jenkins这个用户,shell用的不一样。

 

 

一开始的错误,实际上是找不到这个路径,因为默认是~/.m2/repository。于是maven直接去找私服了。然而,我根本没有把这玩意放在私服上——因为没必要。

[ERROR]   The project com.fbysss.dev:sssApp:${project.build.version}(/var/lib/jenkins/jobs/sssApp/workspace/pom.xml) has 1 error

[ERROR]     Non-resolvable parent POM: Failure to findcom.fbysss.dev:sssApp-pom:pom:1.0.0 in http://nexus.fbysss.com/content/groups/public/ was cached in the local repository, resolution will notbe reattempted until the update interval of central has elapsed or updates areforced and 'parent.relativePath' points at wrong local POM @ line 6, column 10-> [Help 2]

后来才是无法访问。

[ERROR] Could notcreate local repository at /home/sss/.m2/repository -> [Help 1]

原来是jenkins访问不了/home/sss,所以,把local repository设置在这里是不明智的。

打开settings.xml,设置目录为/var/mavenrepo

 

 

于是,

mkdir /var/maven-repo

cp /home/sss/.m2 /var/maven-repo/. -r

chmod 777 /var/maven-repo

 

新问题又来了:

因为jenkins一启动,虚拟机就很慢。估计jetty还是占用了不少内存。直接把war包放到tomcat下面应该是更好的选择。

 

但是,war包部署到tomcat下,访问发现之前的数据全部没有了。咋办?

vi  /var/lib/jenkins/users/admin/config.xml,可以看到,jenkins就是使用文件存储的方式。

但拷贝过去还是不好用,而且速度没变快。因此还是使用jetty启动。

 

 

问题:Tomcat和Jetty莫名自动关停。

估计内存不足,增加了1G内存。暂时没问题。

 

小技巧:要查看详细信息,可以在Goals中增加一条:-e

  


五、WebHook配置:解决:gitlab push之后,jenkins自动构建

https://wiki.jenkins-ci.org/display/jenkins/gitlab+hook+plugin

 首先,在gitlab中,选中一个project进行编辑

点击web hooks->Push events,添加一个urlhttp://jenkins.fbysss.com/git/notifyCommit?url=git@dev.fbysss.com:app-dev/sssApp.git

测试,提示错误:Hook execution failed. Ensure hook URL is correct and service is up.

单独将这个url放到地址栏里面,提示:

 

No Git consumers using SCM API plugin for: git@dev.fbysss.com:app-dev/sssApp.git

参考如下网址:

http://stackoverflow.com/questions/23000199/jenkins-job-notification-fails-with-no-git-consumers-for-uri

http://superuser.com/questions/705645/jenkins-notification-poll-build-fail-with-no-git-consumers-for-uri-ssh-path

说的主要是,首先gitlab中的POLL SCM要设置

效果:push到gitlab之后,jenkins自动进行构建。看日志可检查。

 

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值