服务器环境:
Linux版本:CentOS Linux release 7.3.1611 (Core)
Git版本:git version 1.7.1
Git端口:22
1.安装Jenkins
(1)首先要先添加Jenkins源:
sudo wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
(2)添加完成之后直接使用yum命令安装Jenkins:
yum install jenkins
(3)修改Jenkins端口及运行身份
vim /etc/sysconfig/jenkins
(4)启动 / 停止Jenkins
service jenkins start / stop
(5)在浏览器中访问Jenkins界面,http://192.168.12.12:8880
2.创建项目(省略)
3.配置Git
使用ssh协议,搭配公钥
注意⚠️:url为ssh://[email protected]:port/gitPath/projectName
Git在非默认端口,需要添加.git后缀,url为 ssh://[email protected]:8023/git/test.git
Git在默认22端口,则url为 ssh://[email protected]:22/git/test
在Jenkins服务器上生成SSH Key
cd ~/.ssh
ssh-****** -t rsa -C "[email protected]",一直回车,会生成一对文件(id_rsa , id_rsa.pub),id_rsa为私钥,id_rsa.pub为公钥
需要在Git服务器上的~/.ssh/authorized_keys文件中添加Jenkins服务器上生成的公钥
Credentials选择SSH认证方式
Username与url中user保持一致
Key为Jenkins服务器上生成的私钥