要实现gitlab和jenkins的自动触发集成,我们需要安装以下插件:
如果安装插件比较慢,可以更换升级站点位置在:
graph LR
ManageJenkins-->ManagePlugins
ManagePlugins-->高级
高级-->升级站点
升级站点-->https://updates.jenkins.io/update-center.json
这里把https://updates.jenkins.io/update-center.json
替换成清华的站点中心https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
重启Jenkins服务,重启之后有时候default.json
会恢复到原来的状态,这时候需要修改文件,再重启jenkins服务。
[root@jenkins1 updates]# sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
[root@jenkins1 updates]# systemctl restart jenkins
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64
/usr/bin/git
/usr/local/apache-maven
在Jenkins主机操作:
[root@jenkins1 ~]# ssh-keygen #连续按三次回车
[root@jenkins1 ~]# cat .ssh/id_rsa.pub #查看公钥拷贝gitlab
***...***
登录到我们事先安装好的gitlab系统:
右上角点击帐号头像--settings--SSH Keys
jenkins主机测试免密clone代码:
[root@jenkins1 project]# git clone ssh://git@192.168.12.23:10022/lym/test.git
正克隆到 'test'...
The authenticity of host '[192.168.12.23]:10022 ([192.168.12.23]:10022)' ...
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.12.23]:10022' (ECDSA) to the list of known hosts.
...
接收对象中: 100% (47/47), done.
处理 delta 中: 100% (2/2), done.
[root@jenkins1 project]# ls
test
登录jenkins首页--凭据(Credentials)--全局--添加凭据
查看jenkins主机的私钥,填入:
[root@jenkins1 project]# cat ~/.ssh/id_rsa
***...***
也可以使用gitlab系统中的用户名和密码来创建凭据。
token:HqexPyiaMK8zkoZaP5yN
这里主要是配置访问GitLab服务器拉取代码,还有配置ssh远程服务器地址,邮件,目的是为了打包后上传文件到远程服务器。
Manage Jenkins -- Configure System
http://192.168.12.26:8080/
16***814@qq.com
(这里必须配置,否则后面的邮件配置发送不成功)HqexPyiaMK8zkoZaP5yN
Publish over SSH只填写Key内容: 远程主机的私钥。
至此,基本配置完成,可以创建task任务了。