使用git+jenkins实现持续集成
构建一个自由风格的php-deploy
Gernal配置,丢弃旧的构建,防止jenkins构建较多之后变臃肿
源码管理:这里使用git插件,也可以使用svn插件
将git路径存在这里还需要权限认证,否则会出现error 。
jenkins服务器上生成SSH-Key
[root@linux-node2 ~]# yum install -y git[root@linux-node2 ~]# ssh-keygen Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'.Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:SHA256:00FQjn5P6qAtok4BuE42TyfuNJnblzZ389XwKBhmHjY root@linux-node2The key's randomart image is:+---[RSA 2048]----+| .oo ||. + ||o . o || o . . . ||.+.o . S E . . ||+ =.= B O +.|| ..B o + o ..o|| .o = .B + o .. || .o+ o+.+ o o. |+----[SHA256]-----+[root@linux-node2 ~]# cat .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+/XyUMNP5Wm63hhcACosVyRtmJxTSnT46HSKZ2PhduTHPIJcfhVTmeCk1zwO0fP8PmwXFf0+G9ki8CupE/+xcOy14TCqxNgvP8o514IjXOFV7SO1lnHKH3t0RfaFEloRZHnrgIcWiZrFvYRT/TFznWO86sfHPzlW6WF9elTqRURNR60bwv9C6iw4PpYjGVIST/SeGl75axtUjJr544jB5pEWtNZ09ktCKpPeFBvgCc9exdzOQuzaCXQrroNU0p6MB6KkoIOmpkN92cDPdg4EgBYDjwcl38FbXOq3N0QL8PT+IZpHBWFVEAZU2alI02H5NNUy9p2K/Br4NY3UvYZiP root@linux-node2
命令行测试添加ssh-key后能否正常拉取[root@linux-node2 ~]# git clone git@192.168.56.11:java/app1.gitCloning into 'app1'...The authenticity of host '192.168.56.11 (192.168.56.11)' can't be established.ECDSA key fingerprint is SHA256:p2lhKmsPQ6K+dWHHvbJg0GV+Ni9VM7vlViKrYsZLP1s.ECDSA key fingerprint is MD5:22:14:1c:37:de:47:1c:4a:2f:88:b1:dc:e2:d0:02:17.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '192.168.56.11' (ECDSA) to the list of known hosts.remote: Counting objects: 11, done.remote: Compressing objects: 100% (7/7), done.remote: Total 11 (delta 0), reused 11 (delta 0)Receiving objects: 100% (11/11), done.[root@linux-node2 ~]# lltotal 68048-rw-------. 1 root root 948 Dec 3 01:26 anaconda-ks.cfgdrwxr-xr-x 3 root root 62 Dec 21 15:53 app1-rw-r--r-- 1 root root 69675984 Mar 2 2017 jenkins-2.32.3-1.1.noarch.rpm
然后保存,立即构建一次,会拉取master的代码库
点开可以看到控制台的输出,如图:
/var/lib/jenkins/workspace/php-deploy目录用于存放代码信息[root@linux-node2 php-deploy]# lltotal 12-rw-r--r-- 1 root root 28 Dec 21 16:11 index.html-rw-r--r-- 1 root root 12 Dec 21 16:11 new.html-rw-r--r-- 1 root root 19 Dec 21 16:11 readme[root@linux-node2 php-deploy]# pwd/var/lib/jenkins/workspace/php-deploy
这里我们拉取的代码需要推送到远程代码目录,需要如下操作:
架设linux-node1为web服务,目录为/data/www/php-deploy
[root@linux-node1 ~]# mkdir /data/www/php-deploy -p添加node2的免秘钥登陆[root@linux-node1 ~]# vim .ssh/authorized_keys[root@linux-node1 ~]# chmod 600 .ssh/authorized_keys [root@linux-node2 ~]# ssh 192.168.56.11Last login: Mon Dec 4 17:41:56 2017 from 192.168.56.1[root@linux-node1 ~]#
修改项目设置,配置构建:Execute shell,相当于将代码自动发布到linux-node1的代码目录中。
接下来,我们重新构建一次,并查看控制台输出:
在node1上查看目录,也会有相应的代码信息[root@linux-node1 ~]# ll /data/www/php-deploy/total 12-rw-r--r-- 1 root root 28 Dec 21 16:11 index.html-rw-r--r-- 1 root root 12 Dec 21 16:11 new.html-rw-r--r-- 1 root root 19 Dec 21 16:11 readme[root@linux-node1 ~]#
热门评论
您这个是讲怎么用的 , 请问有怎么在服务器搭建jenkins + gitlab么