git ci编译打包java_使用Gitlab CI将每个构建部署到服务器

本文介绍了如何利用GitLab CI/CD和gitlab-runner进行自动化部署。通过配置runners.ssh,可以将Java项目部署到指定服务器。在.gitlab-ci.yml文件中定义部署任务,并设置相应标签,当代码推送到GitLab时,匹配标签的gitlab-runner会执行部署脚本,如`npm install && forever restartall`,实现应用的更新。
摘要由CSDN通过智能技术生成

您可以使用gitlab-ci和gitlab-runner [runners.ssh]来部署到单个或多个服务器 .

流程:

(git_project with yml file) --> (gitlab && gitlab-ci) --> (gitlabrunner) ---runners.ssh---> (deployed_server,[deploye_server2])

你需要将gitlab-runner注册到gitlab-ci并在gitlab web上将标签设置为delpoyServer . /etc/gitlab-runner/config.toml:

[[runners]]

url = "http://your.gitlab.server/ci"

token = "1ba879596cf3ff778ee744e6decedd"

name = "deployServer1"

limit = 1

executor = "ssh"

builds_dir = "/data/git_build"

[runners.ssh]

user = "you_user_name"

host = "${the_destionation_of_deployServer_IP1}"

port = "22"

identity_file = "/home/you_user_name/.ssh/id_rsa"

[[runners]]

url = "http://your.gitlab.server/ci"

token = "1ba879596cf3ff778ee744e6decedd"

name = "deployServer2"

limit = 1

executor = "ssh"

builds_dir = "/data/git_build"

[runners.ssh]

user = "you_user_name"

host = "${the_destionation_of_deployServer_IP2}"

port = "22"

identity_file = "/home/you_user_name/.ssh/id_rsa"

runner.ssh表示,跑步者将登录 ${the_destionation_of_deployServer_IP1} 和 ${the_destionation_of_deployServer_IP2} ,然后将项目克隆为 builds_dir .

编写yml文件,例如:.gitlab-ci.yml

job_deploy:

stage: deploy

tags: delpoyServer1

script:

- npm install && forever restartall

job_deploy:

stage: deploy

tags: delpoyServer2

script:

- npm install && forever restartall

将你的gitlab-runner设置为'http://your.gitlab.server/ci/admin/runners'中的 delpoyServer1 和 delpoyServer2 标签

当你将代码推送到gitlab时

gitlab-ci服务器将解析您项目中的 .gitlab-ci.yml 文件,选择带有标签的跑步者: deployServer1 或 deployServer2 ;

带有deployServer1标签的 gitlab-runner 将使用ssh登录 ${the_destionation_of_deployServer_IP1} 和 ${the_destionation_of_deployServer_IP2} ,将项目克隆为 builds_dir ,然后执行脚本:npm install && forever restartall .

链接:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值