前言告别手动打包部署到服务器,搭建自动化集成环境……这里是gitlab-ci工具服务器配置gitlab-runner1。安装gitlab-ci-multi-runner参考:https://mirrors.tuna.tsinghua.edu.cn/help/gitlab-ci-multi-runner/2。查看gitlab-runner运行状态gitlab-runnerstatus3.注册runnergitlab-runnerregister例子:以system-mode运行。Pleaseenterthegitlab-cicoordinatorURL(e.g.https://gitlab.com/):http://192.168.xxx.xxx///这里输入gitlab安装的服务器ip/或域名Pleaseenterthegitlab-citokenforthisrunner:eaYyokc57xxZbzAsoshT//这里的token可以通过Gitlab上的项目Runners选项查看。Pleaseenterthegitlab-cidescriptionforthisrunner:[E5]:ci-demo//在这里填写一个描述,这并不重要。Pleaseenterthegitlab-citagsforthisrunner(commaseparated):demo//这里填写标签信息,多个标签可以用逗号分隔。Registeringrunner...succeededrunner=eaYyokc5Pleaseentertheexecutor:docker+machine,docker-ssh+machine,kubernetes,custom,docker,docker-ssh,parallels,virtualbox,shell,ssh:shell//这里需要输入runner的Execution方法,因为我的Gitlab和runner是安全的安装在同一台服务器上,直接输入shellRunner注册成功。随意启动它,但如果它已经在运行,配置应该会自动重新加载!//如果出现此消息,则表示服务器配置已成功完成。如果需要使用来自动构建,需要另外添加一个配置文件项目配置构建脚本。gitlab-ci.yml文件在项目根目录下添加上述文件,并添加以下脚本stages:-build//测试环境buildbuild-test:stage:buildscript:-npminstall-npmrunbuild-test-rm-rf/www/tutu-xxxx/dist-cp-adist/www/tutu-xxxx/only:-devtags:-test-tutu-xxxx测试是否成功将测试分支代码直接推送到远程服务器看是否管道正在构建代码。如果是这样,恭喜。之后直接push即可部署,无需手动中转。多台服务器部署在Settings>Repository>deploymentkey中写入主服务器的sshpublickey。在主服务器写一个.sh脚本从其他服务器拉取仓库代码完成多台服务器的同时部署#!/bin/bashfornamein192.168.xxxx1192.168.xxxx2192.168.xxx3192.168.xxx4;do/usr/bin/rsync-avP-e'ssh-p58422'--delete/www/www.xxoo.comroot@"$name":/www/done命令解释:同步/www/www2.xxoo.主服务器下的com目录文件到上诉遍历的服务器部署失败常见问题权限问题permissiondeny;文件的读写权限不够,改一下chmod-Rxxxxnpm相关包安装失败,更换包版本或alternative;或使用纱线包装管理,npmswitchyarn一步到位,教程参考如下:https://yarnpkg.com/en/docs/i...本地:cnpminstallyarn-g//switchinstallationsourceyarnconfigsetregistry'https://problemwithregistry.npm.taobao.org'gitlab-runner12.0.0升级服务器git版本到2.x
