我已经设置了一个项目,并为其配置了一个Gitlab运行器,以设置自己的Gitlab服务器。我是持续集成服务器的新手,因此不知道如何完成以下任务。
每次我提交到项目的master分支时,我都希望将存储库部署到另一台服务器,并在其中运行两个shell命令(npm install和foreverrestartall)。
npm install
foreverrestartall
我该怎么做?我也需要在部署项目的机器上安装运行程序吗?
您可以使用gitlab-ci和gitlab-runner [runners.ssh]部署到单个或多个服务器。
流程:
(git_project with yml file) --> (gitlab && gitlab-ci) --> (gitlabrunner) ---runners.ssh---> (deployed_server,[deploye_server2])
[[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。
${the_destionation_of_deployServer_IP1}
${the_destionation_of_deployServer_IP2}
builds_dir
job_deploy: stage: deploy tags: delpoyServer1 script: - npm install && forever restartall job_deploy: stage: deploy tags: delpoyServer2 script: - npm install && forever restartall
将您的gitlab-runner设置为,delpoyServer1并delpoyServer2在’ http://your.gitlab.server/ci/admin/runners ‘
delpoyServer1
delpoyServer2
.gitlab-ci.yml
deployServer1
deployServer2
gitlab-runner
链接: