Git 、Jenkins (三)Jenkins 安装部署
Git 、Jenkins (三)Jenkins 安装部署
Git 、Jenkins (三)Jenkins 安装部署
一、jenkins安装
http://updates.jenkins-ci.org/download/plugins/
# Jenkins 插件离线包地址
#导入Jenkins安装所需要的的包
[root@jenkins ~]# ls
jenkins-2.197-1.1.noarch_.rpm plugins.tar.gz # Jenkins插件包
#安装jenkins
[root@jenkins ~]# yum install -y java # 安装Java环境
[root@jenkins ~]# yum localinstall *.rpm # RPM包
[root@jenkins ~]# rpm -ql jenkins #查看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
[root@jenkins ~]# vim /etc/sysconfig/jenkins #修改配置文件
启动用户修改为root
JENKINS_USER="root"
[root@jenkins ~]# systemctl restart jenkins #启动Jenkins
[root@jenkins ~]# route del -net 0.0.0.0/0 gw 10.0.0.254 #删除网关
[root@jenkins ~]# tar xf plugins.tar.gz
[root@jenkins ~]# ll
total 251908
-rw-------. 1 root root 1557 Apr 1 16:09 anaconda-ks.cfg
-rw-r--r--. 1 root root 501 Apr 2 10:17 host_ip.sh
-rw-r--r-- 1 root root 78115455 Sep 28 2019 jenkins-2.197-1.1.noarch_.rpm
drwxr-xr-x 97 jenkins jenkins 8192 Dec 8 2017 plugins
-rw-r--r-- 1 root root 164431230 Nov 26 14:32 plugins.tar.gz
[root@jenkins ~]# cp -a plugins/* /var/lib/jenkins/plugins/ # 覆盖插件目录
[root@jenkins ~]# ll /var/lib/jenkins/plugins/ #查看安装的插件
[root@jenkins ~]# systemctl restart jenkins.service # 重启Jenkins
[root@jenkins ~]# systemctl restart network #重启网卡
浏览器访问:http://10.0.0.15:8080
[root@jenkins ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
6223a0f155d04950ba5ff2896ed03f32
二、Jenkins主要目录
[root@jenkins ~]# rpm -ql jenkins
/etc/init.d/jenkins #jenkins的启动文件
/etc/logrotate.d/jenkins
/etc/sysconfig/jenkins #jenkins的配置文件
/usr/lib/jenkins
/usr/lib/jenkins/jenkins.war #jenkins的程序war包
/usr/sbin/rcjenkins #jenkins的为二进制文件
/var/cache/jenkins #jenkins的程序文件,运行程序解压出来的
/var/lib/jenkins #jenkins的主目录
/var/log/jenkins #jenkins的日志文件/usr/lib/jenkins/ #jenkins安装目录,WAR包会放在这里
/etc/sysconfig/jenkins #jenkins配置文件,“端口”,“JENKINS_HOME”等都可以在这里配置
/var/lib/jenkins/ #默认的JENKINS_HOME
/var/log/jenkins/jenkins.log #Jenkins日志文件
三、构建项目
1.创建一个自由风格的项目
2.配置项目,丢失旧的构建
3.将gitlab和Jenkins关联, 源码管理
1)这里我们需要吧jenkins服务器的公钥给gitlab
jenkins端生成公钥
[root@jenkins ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:crP6VYk8y2aGYD01nkH83fLVEZQKnEKqmZuqT8RN5as root@jenkins
The key's randomart image is:
+---[RSA 2048]----+
| ..oo . .oo|
| o .o.+ o |
| . o =.....o|
| . o +..+ =.oo +|
| o =+.S * o o.|
| . .++ * + .|
| . E o B |
| . . . = |
| .oo ... |
+----[SHA256]-----+
[root@jenkins ~]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUB3yYS+D+SQaX4IDUG9eEH4JDbLSEQoWKz35Uy8BVQx/WAiMpTnwx1KfihLU+WVGeju6h3nEkHqXtlxQPkw96oOhpAT5KtkcCbN111yul+k9EgY0dEj4Nj8uPOD0wLnJTRzNHcHW7XaotEvABIMn0AaVb6NTI6ceFGYeJevyca0qQj9ggdoMWdsx/UE/aSHkrGwirM48dxuoIkkLQUV6PZM+BC0/cieZLUVzc8Zj9HrcGK2L7GzXWhXtINxV0PG99SVhCQ0EnIFiIVlZfeLBBUpOQs5uo6HGIDwtGPJvbx8+7FIAflxmUI5DjeqMPJGgB+eKR9SCwAmPwp2oH084F root@jenkins
2)把公钥给gitlab
3)Jenkins关联gitlab
[root@jenkins ~]# git ls-remote -h git@10.0.0.14:xiaopang/monitor.git
The authenticity of host '10.0.0.14 (10.0.0.14)' can't be established.
ECDSA key fingerprint is SHA256:Lve0lFJS0vTU/UErKoqlvQcIFN9RSk6sZgNDbijVTcs.
ECDSA key fingerprint is MD5:38:c0:e0:c9:34:7c:4e:3e:fb:c1:fe:e8:e2:9c:08:0a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.14' (ECDSA) to the list of known hosts.
f6070e120d59611cb7c66eda7c979e58f446be75 refs/heads/master
4)构建触发器
选择第四隔点击高级
5)添加gitlab端web钩子
解决办法
完成!