前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >jenkins的配置

jenkins的配置

作者头像
院长技术
发布2022-03-11 11:35:13
7780
发布2022-03-11 11:35:13
举报
文章被收录于专栏:院长运维开发

jenkins的配置(二)

一.插件安装:

要实现gitlab和jenkins的自动触发集成,我们需要安装以下插件:

  • Gitlab 和 Gitlab Hook 用于从gitlab或取代
  • Git plugin 和 Git Client plugin,用于jenkins在gitlab中拉取代码
  • Gitlab Authentication,用于gitlab和jenkins认证
  • SSH 和Pusblish Over SSH 用于远程执行shell脚本和通过ssh部署应用。
  • Build Authorization Token Root 和 Build Token Trigger,用于构建和触发。
  • Maven Integration和Pipeline Maven Integration,用于新建maven项目。

如果安装插件比较慢,可以更换升级站点位置在:

代码语言:javascript
复制
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服务。

代码语言:javascript
复制
[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

二.Global Tool Configuration

1、JDK配置:

  1. 别名:JDK1.8.0_242(随便写也可以查看主机jdk版本)
  2. 取消勾选Install automatically
  3. JAVA_HOME: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64

2、Git配置

  1. Name: jenkins_git (自定义命名)
  2. 取消勾选Install automatically
  3. Path to Git executable:/usr/bin/git

3、Maven配置

  1. Maven Name:jenkins_maven (自定义命名)
  2. 取消勾选Install automatically
  3. MAVEN_HOME: /usr/local/apache-maven

4、Docker安装(选装)

  1. Docker Name:jenkins_docker (自定义命名)
  2. 勾选Install automatically (自动安装)

三.配置秘钥

1.配置jenkins主机免密拉取gitlab代码

在Jenkins主机操作:

代码语言:javascript
复制
[root@jenkins1 ~]# ssh-keygen        #连续按三次回车
[root@jenkins1 ~]# cat .ssh/id_rsa.pub     #查看公钥拷贝gitlab
***...***

登录到我们事先安装好的gitlab系统:

右上角点击帐号头像--settings--SSH Keys

image
image

jenkins主机测试免密clone代码:

代码语言:javascript
复制
[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

2、添加jenkins系统访问gitlab系统的凭据

(1)ssh秘钥类型

登录jenkins首页--凭据(Credentials)--全局--添加凭据

image
image

查看jenkins主机的私钥,填入:

代码语言:javascript
复制
[root@jenkins1 project]# cat ~/.ssh/id_rsa
***...***
image
image
(2)用户名密码类型

也可以使用gitlab系统中的用户名和密码来创建凭据。

image
image
(3)Gitlab API token 类型
image
image
image
image

token:HqexPyiaMK8zkoZaP5yN

三. 全局系统配置

这里主要是配置访问GitLab服务器拉取代码,还有配置ssh远程服务器地址,邮件,目的是为了打包后上传文件到远程服务器。

Manage Jenkins -- Configure System

1、Jenkins Location

  • Jenkins URL:http://192.168.12.26:8080/
  • 系统管理员邮件地址: 16***814@qq.com(这里必须配置,否则后面的邮件配置发送不成功)

2、Gitlab

  • Connection name :gitlab (自定义命名)
  • Gitlab host URL:http://192.168.12.23 (gitlab web地址)
  • Credentials:Gitlab API token(选择之前添加的API凭据)
image
image

3、Git plugin

  • Global Config user.name Value:root(使用git配置用户)
  • Global Config user.email Value:xxxxxxx@qq.com (使用git配置用户邮箱)

4、Gitlab Notifier Configuration

  • Gitlab URL:192.168.12.23
  • Gitlab token: HqexPyiaMK8zkoZaP5yN
  • [ ] Send notification as commit statuses 勾选

5、Extended E-mail Notification

  • SMTP server: smtp.qq.com
  • Default user E-mail suffix : @qq.com (默认邮件后缀名)

6、邮件通知

  • SMTP服务器:smtp.qq.com
  • 用户默认邮件后缀:@qq.com
  • [ ] 使用SMTP认证 勾选✔
  • 用户名:xxxxxxx@qq.com -密码: **(qq邮箱授权码)
  • [ ] 使用SSL协议 勾选 ✔
  • SMTP端口 :465
  • 字符集:UTF-8
image
image

7、Publish over SSH

Publish over SSH只填写Key内容: 远程主机的私钥。

8、SSH Server

  1. Name: 192.168.12.23webserver (自定义名称)
  2. Hostname:192.168.12.23 (远程主机ip)
  3. Username:root (登录的用户名)
  4. Remote Directory:/data/ (远程传输文件的目录)
  5. [ ] Use password authentication, or use a different key 勾选✔
  6. Passphrase / Password:123456 (远程主机密码)
  7. Key:远程主机私钥

至此,基本配置完成,可以创建task任务了。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • jenkins的配置(二)
    • 一.插件安装:
      • 二.Global Tool Configuration
        • 1、JDK配置:
        • 2、Git配置
        • 3、Maven配置
        • 4、Docker安装(选装)
      • 三.配置秘钥
        • 1.配置jenkins主机免密拉取gitlab代码
        • 2、添加jenkins系统访问gitlab系统的凭据
      • 三. 全局系统配置
        • 1、Jenkins Location
        • 2、Gitlab
        • 3、Git plugin
        • 4、Gitlab Notifier Configuration
        • 5、Extended E-mail Notification
        • 6、邮件通知
        • 7、Publish over SSH
        • 8、SSH Server
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档