思路图:php
jenkins-->系统管理-->管理插件-->下载并安装gitlab pluginhtml
路径:Jenkins-->Credentials-->System-->Global credentials(unrestricted)-->Add Credentialsjava
一、Kind选择Gitlab API tokennode
二、其中API token填写gitlab中有库权限的帐号linux
三、ID填写用户帐号nginx
gitlab生成Api token,将生成的token填入上面的证书内。git
路径:系统管理-->系统设置程序员
一、填写链接名web
二、填写gitlab访问URLapp
三、选择gitlab认证
三、测试链接
在job配置界面
一、勾选 Build when a change is pushed to GitLab. GitLab CI Service URL: http://192.168.56.12:8080/project/php-deploy
二、选择push events 时间触发构建
三、选择分支过滤(此处能够根据不一样的需求来使用过滤功能)
四、secret token须要填入gitlab项目中的webhook
在gitlab中找到项目-->setting-->Integrations配置
填写在上图生成的连接:
URL:http://192.168.56.12:8080/project/php-deploy
Secret Token:3f199086a22c54957579966e34ad120a
点击Add webhook
测试是否生效:点击test-->选择push event会跳转到Hook excuted successfully:HTTP 200
在linux-node1上安装nginx,初始同步了线上代码,写入一个index.html。如图:
[root@linux-node1 ~]# ll /data/www/php-deploy/ total 12 -rw-r--r-- 1 root root 28 Dec 23 15:45 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 ~]# cat /data/www/php-deploy/index.html <h1>welcome to beijing</h1>
模拟程序员在linux-node2上进行修改代码,并提交到gitlab的master分支上
[root@linux-node2 app1]# pwd /root/php/app1 [root@linux-node2 app1]# echo "Welcome to use Jenkins and Gitlab" > index.html [root@linux-node2 app1]# git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # #modified: index.html # no changes added to commit (use "git add" and/or "git commit -a") [root@linux-node2 app1]# git add . [root@linux-node2 app1]# git commit -m "jenkins + gitlab" [master 7313bdd] jenkins + gitlab 1 file changed, 1 insertion(+), 1 deletion(-) [root@linux-node2 app1]# git push origin master Counting objects: 5, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 334 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@192.168.56.11:java/app1.git dd37af6..7313bdd master -> master
到此,自动触发和发布就完成了!这只是一个简单的构建发布,做为内部测试使用仍是能够的!生产使用,有待优化!