一. java -jar jenkins.war方式运行(不推荐)
1. 下载并安装
#下载
[root@node02 ~]# wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war
#运行
[root@node02 ~]# java -jar jenkins.war --httpPort=8888
保存密码
访问jenkins http://192.168.2.44:8888
选择插件安装
因为在构建的过程中都是使用
Pipelines
来操作的,所以Pipelines
这一列都勾选上创建一个账号
2. 测试
创建一个项目
保存
构建
二. yum方式安装(推荐)
一个是最新版的,一个是稳定版的。
下载并安装
[root@wanfei ~]# sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
[root@wanfei ~]# sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
[root@wanfei ~]# sudo yum install jenkins
修改端口
[root@wanfei ~]# vi /etc/sysconfig/jenkins
#修改
JENKINS_PORT="8080"
JENKINS_PORT="8888"
启动
[root@wanfei ~]# service jenkins restart
Restarting jenkins (via systemctl): [ OK ]
访问jenkins http://192.168.2.44:8888
从下面文件可以查看到密码(一次性的,输入后就自动删除了)
接下来和上面一样 --->选择插件安装
三. yum安装jenkins,生成ssh key,并测试连接
使用yum安装jenkins要切换jenkins生成ssh key保存到git上,jenkins才能连上
3.1 切换jenkins用户生成ssh key
#切换用户没反应
[root@wanfei ~]# su jenkins
#jenkins安装后修改了配置,改回来
[root@wanfei ~]# sudo vim /etc/passwd
jenkins:x:996:992:Jenkins Automation Server:/var/lib/jenkins:/bin/false #修改
jenkins:x:996:992:Jenkins Automation Server:/var/lib/jenkins:/bin/bash
[root@wanfei ~]# su jenkins
#发现前面的是bash-4.2
bash-4.2$ vim ~/.bash_profile
#没有文件的话创建新文件,添加
export PS1='[\u@\h \W]\$'
#生效
bash-4.2$ source ~/.bash_profile
#切换到root,删除以前生成的ssh key
[jenkins@wanfei root]$su root
Password:
[root@wanfei ~]#cd .ssh
[root@wanfei .ssh]#ls
id_rsa id_rsa.pub known_hosts
[root@wanfei .ssh]#rm -rf id_*
[root@wanfei .ssh]#ls
known_hosts
#清空
[root@wanfei .ssh]#vi known_hosts
[root@wanfei .ssh]#cd ~
[root@wanfei ~]#su jenkins
[jenkins@wanfei root]$cd ~/.ssh
[jenkins@wanfei .ssh]$ls
known_hosts
#清空
[jenkins@wanfei .ssh]$vi known_hosts
[jenkins@wanfei .ssh]$ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/jenkins/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/jenkins/.ssh/id_rsa.
Your public key has been saved in /var/lib/jenkins/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:XkaQ3TC8q/lsGAsaO4IndWD1HQP03xN/s5H1wrRmTaQ jenkins@wanfei
The key's randomart image is:
+---[RSA 2048]----+
| .o..+oo .|
| . .+.o.. o |
| . . ..o... E o|
| o . .o.. = ++|
| . . S +.o B++|
| . o ...o. + o+|
| o . + ..* . |
|o o + =.. |
| o . . oo |
+----[SHA256]-----+
[jenkins@wanfei .ssh]$ls
id_rsa id_rsa.pub known_hosts
#查看ssh key
[jenkins@wanfei .ssh]$vi id_rsa.pub
[1]+ Stopped vi id_rsa.pub
#切换root
[root@wanfei ~]#cd ~/.ssh
[root@wanfei .ssh]#ls
known_hosts
[root@wanfei .ssh]#cd /var/lib/jenkins/.ssh
[root@wanfei .ssh]#ls
id_rsa id_rsa.pub known_hosts
[root@wanfei .ssh]#scp id_rsa* ~/.ssh
[root@wanfei .ssh]#cd ~/.ssh
[root@wanfei .ssh]#ls
id_rsa id_rsa.pub known_hosts
3.2 在jenkins上测试连接gitlab下载代码
随便创建一个项目
测试连接配置
Add Jenkins
得到错误原因
jenkins服务器执行(测试失败了,但jenkins工gitlab拉代码成功了,后续。。。)
git ls-remote -h ssh://git@47.99.37.64:2222/www19930327/mybatisplus-springmvc.git HEAD