gitlab+jenkins+maven自动构建
环境
192.168.48.52 gitlab
192.168.48.53 jenkins maven
192.168.48.56 web
web
web项目tomcat8
文件目录在/home/apache-tomcat-8.5.42/webapps/
[root@web ~]# ll /home/apache-tomcat-8.5.42/webapps/
total 4
drwxr-x--- 3 root root 306 Jun 29 14:28 ROOT
web服务器生成公钥和私钥
[root@web webapps]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:hJneR/uJld2SAh4rR4ulor1QGlrQ7iKw3KVvfkR9Hms root@web
The key's randomart image is:
+---[RSA 2048]----+
| |
| . + |
| . . + o * |
| o . + O O o o |
|. +.= S X * + .|
|o..+o* o + E o . |
|o.oo= o o o |
| . ..o o |
| ooo |
+----[SHA256]-----+
[root@web webapps]# ssh-copy-id web
[root@web webapps]# ssh-copy-id gitlab
[root@web webapps]# ssh-copy-id jenkins
##查看私钥
[root@web webapps]# cat /root/.ssh/id_rsa
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA0qaZXqZvjFwmRj2GKZVlZ2UGR+/KUZ5P4XuJxuncCIsKhCAl
eK71ro0icr/NvXhtF2ewhtZRgCplwvF64jpLvElgEhtPuNX5QKoh19gZ8lAVZ90u
BOsz5xt6QLgtHkGBu3IL8ZePrat/eqawI5xu2hgYQpAvdHMdBnplz2eAV3ym2h+1
HK1VgLePni83gPmRIDIhGhv62pxYM4korrMBVJcn/nOdgW4MozLRne9WHpOBz1IO
AlCbIQWfXzWVBwExpWs7oEQMnfciMr5sTZN3WChybZoAL8ebigX42I7vEMegdnnK
MEaMO0TwvCZYFgpenSrKCIebpfWPpocaQBVmBwIDAQABAoIBAFev9C4bWFn0ThZ1
K/EJeJHG0wuE/RJmtVfmhh7gYLDJuFHx08deBXVo2MstnqZdiAPzLN+kPX79py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/pVquuFv8UHOBiWgwP91sYxaOKV2hp
Y6hPPhDDyYmEcBYAwDTWvDi2WP69T7t/v8egCNAbWR5+aLOrhpWzDw==
-----END RSA PRIVATE KEY-----
jenkins
安装插件
Build Authorization Token Root
Publish Over SSH
Gitlab Authentication
Git Parameter
配置ssh
配置gitlab
获取gitlab token
o4nxpb3RMFqQ8_dsMPK3
jenkins添加token
jenkins配置gitlab
配置gitlab webhook
jenkins配置项目test01
记住url和token
http://192.168.48.53:8080/project/test01
e336692801d924617fb626c6ec68e927
gitlab配置web hook
错误解决
用root账号登录
开启参数
重新配置web hook
测试 web hook
构建项目
查看输出日志
访问web试试
测试是否自动构建
修改gitlab上代码
[root@gitlab ~]# cd test/
[root@gitlab test]# ll -h
total 4.0K
-rw-r--r-- 1 root root 962 Jun 29 14:53 pom.xml
-rw-r--r-- 1 root root 0 Jun 29 15:00 README.md
drwxr-xr-x 3 root root 18 May 23 2014 src
[root@gitlab test]# vim src/main/webapp/index.jsp
<!-- add java -->
<%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<p>
It is now
<%= new java.util.Date() %></p>
<p>
You are coming from
<%= request.getRemoteAddr() %></p>
<!-- add session id -->
<h1><font color="red">Session serviced by tomcat</font></h1>
<table aligh="center" border="1">
<tr>
<td>Session ID</td>
<td><%=session.getId() %></td>
<% session.setAttribute("abc","abc");%>
</tr>
<tr>
<td>Created on</td>
<td><%= session.getCreationTime() %></td>
</tr>
</body>
[root@gitlab test]# git add .
[root@gitlab test]# git commit -m 'add session'
[master b8282fe] add session
1 file changed, 17 insertions(+), 1 deletion(-)
[root@gitlab test]# git push origin master
Counting objects: 11, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 752 bytes | 0 bytes/s, done.
Total 6 (delta 1), reused 0 (delta 0)
To git@192.168.48.52:test01/test.git
b0ef455..b8282fe master -> master