侧边栏壁纸
博主头像
爱运维 博主等级

行动起来,活在当下

  • 累计撰写 197 篇文章
  • 累计创建 143 个标签
  • 累计收到 21 条评论

目 录CONTENT

文章目录

Jenkins+GitLib持续集成[三]Jenkins+gitlab通过rsync发布更新web

Administrator
2017-02-17 / 2 评论 / 0 点赞 / 1 阅读 / 0 字

Jenkins+GitLib持续集成[一]介绍及安装gitlab服务:https://www.iyunw.cn/archives/jenkins-gitlib-chi-xu-ji-cheng-yi-jie-shao-ji-zhuang-gitlab-fu-wu/

Jenkins+GitLib持续集成[贰]安装Jenkins:https://www.iyunw.cn/archives/jenkins-gitlib-chi-xu-ji-cheng-er-zhuang-jenkins/

一、通过gitlab构建第一个任务,获取gitlab的代码。

    1.首先,我们需要jenkins能够获取gitlab代码,我们需要在运行jenkins的用户下ssh-keygen生成密钥,然后在gitlab上添加公钥。


[jenkins@lb2 ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jenkins/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/jenkins/.ssh/id_rsa.
Your public key has been saved in /home/jenkins/.ssh/id_rsa.pub.
The key fingerprint is:
bc:33:63:1c:77:d9:66:bf:18:30:eb:64:ab:15:0e:70 jenkins@lb2.iyunw.cn
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|       . E       |
|       .o    o   |
|        S..+o +  |
|       . +o.=o . |
|        B  * .  .|
|       . += . o .|
|         ..o . . |
+-----------------+
     2.去gitlab上添加刚生成的公钥

    在jenkins用户下git测试是否可以通过git工具直接git数据来测试密钥是否正常,有关git命令可以参考廖雪峰的git教程,非常详细


[jenkins@lb2 web]$ git config --global user.name "admin"
[jenkins@lb2 web]$ git config --global user.email 351937287@qq.com
[jenkins@lb2 ~]$ git clone git@lb1:app1/web.git
Initialized empty Git repository in /home/jenkins/web/.git/
remote: Counting objects: 52, done.
remote: Compressing objects: 100% (37/37), done.
remote: Total 52 (delta 12), reused 39 (delta 8)
Receiving objects: 100% (52/52), 55.93 MiB | 7.35 MiB/s, done.
Resolving deltas: 100% (12/12), done.
[jenkins@lb2 ~]$ ls
tomcat  web
[jenkins@lb2 ~]$ cd web
[jenkins@lb2 web]$ ls
123                       Zabbix企业完整 (1).pdf         新建文本文档.txt
SVN服务实战应用指南.docx  新建 WinRAR ZIP 压1缩文件.zip
[jenkins@lb2 web]$ touch 222222222
[jenkins@lb2 web]$ git add --all
[jenkins@lb2 web]$ git commit -m 'add 123'
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
[jenkins@lb2 web]$ git push
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 223 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
To git@lb1:app1/web.git
   117e01c..8915afa  master -> master
     4.然后登录jenkins创建任务








到此  ,可以看到同步成功

二、同步完成我们需要吧代码同步发布到web(rsync)

   1、同样,我们需要jenkins用户免密钥登录web1,因为我们需要rsync同步免密钥


[jenkins@lb2 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub tommy@web1
The authenticity of host 'web1 (192.168.80.210)' can't be established.
RSA key fingerprint is c1:9e:41:da:17:eb:d2:f0:72:1b:a6:97:49:58:3d:50.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'web1,192.168.80.210' (RSA) to the list of known hosts.
tommy@web1's password: 
Now try logging into the machine, with "ssh 'tommy@web1'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.
     我们更新任务,添加构建步骤,执行shell





我们从新执行任务,就可以看到数据无差异同步到了web1  data目录




到此   jenkins+gitlab通过rsync无差异发布就完成


0

评论区