jenkins集成gitlab发布到远程服务器

jenkins集成gitlab发布到远程服务器

前面我们讲了通过创建maven项目部署在jenkins本地服务器,这次实验我们将部署在远程服务器,再以nginx作为前端项目做一个小小的举例

1、部署nginx服务

bash 复制代码
[root@web ~]# docker pull nginx
[root@web ~]# docker images
REPOSITORY        TAG       IMAGE ID       CREATED        SIZE
nginx             latest    be69f2940aaf   7 weeks ago    192MB
[root@web ~]# mkdir -p /web/nginx
[root@web ~]# docker run -p 80:80 --name nginx \
> -v /web/nginx/html:/usr/share/nginx/html \
> -v /web/nginx/logs:/var/log/nginx  \
> -d nginx
954f89431fe4ac4743d3f93a9c357383eac3c07a67c20caca8d6546a686b038d
[root@web ~]# echo "Hello from Nginx" > /web/nginx/html/index.html
[root@localhost ~]# docker restart nginx
[root@localhost ~]# curl 127.0.0.1:80
Hello from Nginx

2、上传代码

gitlab再次创建一个项目,此处省略

bash 复制代码
##修改远程地址
[root@gitlab web]# git remote set-url origin git@192.168.232.135:ops/web.git
[root@gitlab web]# git remote -v
origin	git@192.168.232.135:ops/web.git (fetch)
origin	git@192.168.232.135:ops/web.git (push)
[root@gitlab web]# ls
404.html    assets             blog.html    contact.html  embed.html   index.html         pricing.html  static     说明.htm
about.html  blog-details.html  client.html  course.html   index1.html  landing-page.html  service.html  team.html
[root@gitlab web]# git init
Reinitialized existing Git repository in /root/data/web/.git/
[root@gitlab web]# git config --global user.name "Administrator"
[root@gitlab web]# git config --global user.email "gitlab_admin_0cd627@example.com"
[root@gitlab web]# git add .
[root@gitlab web]# git commit -m "第一次上传"
[root@gitlab web]# git push origin master
  • gitlab查看

3、jenkins web页面配置远端服务器

Dashboard》系统管理》System

  • 最底下测试 (success表示成功)

4、创建一个自由风格的软件项目

4.1 配置远程服务器

  • 关于Source files 的说明
场景 源文件配置 说明
上传 target 目录下的所有文件 target/** 会递归匹配 target 目录下的所有文件和子目录
只上传 jar 文件 target/*.jar 匹配 target 目录下所有 .jar 后缀的文件
上传 dist 目录(前端项目) dist/** 上传 dist 目录下的所有静态文件
  • 关于Remove prefix 的说明

如果你使用了类似 target/** 这样的路径,并且配置了 Remove prefix 为 target/,那么文件传输到远程服务器后,会直接以 target 目录下的文件结构呈现

4.2 远程服务器查看文件

bash 复制代码
[root@web ~]# ls /web/nginx/html/
404.html    assets             blog.html    contact.html  embed.html   index.html         pricing.html  static     说明.htm
about.html  blog-details.html  client.html  course.html   index1.html  landing-page.html  service.html  team.html
  • 浏览器访问
相关推荐
feasibility.39 分钟前
电脑一天重启3次、WiFi还消失:蓝屏0x9F背后,是MT7921网卡撞上Windows电源管理
服务器·网络·windows·wifi·电脑·网卡·驱动
顧棟40 分钟前
INFINI Gateway 启动过程分析
服务器·网络·gateway
xbzb3 小时前
服务器与网络:从一台裸机到能联网跑服务(5 篇)
服务器·网络·ip·raid·blog.csdn.net·article
Hhy_11074 小时前
【Linux 进击之路 · 01】起航篇:从认识操作系统到XShell 远程连接、多叉树目录体系到高频基础指令全解析
linux·服务器·后端·学习
Eyfcom4 小时前
〖物流自动化测试 03〗Chaos Mesh 在物流微服务中的故障注入:从 Pod 宕机到业务逻辑故障的工程实践
服务器·微服务·架构·快递系统·物流自动化测试
xurileidian4 小时前
第 21 篇 · 边玩边学Python · if elif else 与缩进归属
java·服务器·网络
-梅6 小时前
linux网络(1)网络聊天室与网络计算器
linux·运维·服务器
mont evergreen6 小时前
青云宗秘录:libp2p 双节点聊天阵法源码卷
服务器·网络协议·p2p
进击的荆棘19 小时前
Linux网络——传输层协议UDP
linux·运维·服务器·网络·udp
LabVIEW开发1 天前
EXFO IQS-5100B + LabVIEW 光测试怎么做?
服务器·网络·labview