千家信息网

构建gitbook并基于gitlab自动发布~

发表于:2024-09-21 作者:千家信息网编辑
千家信息网最后更新 2024年09月21日,整个构建过程分为以下几个部分: 安装node,npm部署gitbook gitlab版本8以上支持pipelines,服务器上安装,配置gitlab runner。1.安装nodecurl -sL h
千家信息网最后更新 2024年09月21日构建gitbook并基于gitlab自动发布~

整个构建过程分为以下几个部分: 安装node,npm部署gitbook gitlab版本8以上支持pipelines,服务器上安装,配置gitlab runner。

1.安装node

curl -sL https://rpm.nodesource.com/setup_6.x | bash -  (6.9.5)yum install -y nodejs

2.安装gitbook

npm install -g gitbook-cli

3.gitlab-ci实现 gitlab的CI主要通过新版本的pipelines功能。 实现原理: 在部署服务器上运行一个gitlab的runner,并且在gitlab项目的根目录下创建.gitlab-ci.yml文件,里面主要保存一些运行 脚本,当有新数据被push时,就会执行其中的代码,实现持续集成。 实现步骤: 1.在项目根目录下新建.gitlab-ci.yml文件,内容如下

rspec:  script:    - gitbook init    - gitbook build    - sh start.sh

当项目内容更新时,更新的内容就会pull到部署服务器,然后依次执行上面代码,完成gitbook的更新。 2.安装runner到服务器上

#增加gitlab的yum源仓库curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash#yum安装runneryum install gitlab-ci-multi-runner

为了把runner添加到gitlab项目中,需要项目的token和gitlab的url,在服务器上运行如下代码:

gitlab-ci-multi-runner registerPlease enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):your urlPlease enter the gitlab-ci token for this runner:your tokenPlease enter the gitlab-ci description for this runner:[opstest]: Please enter the gitlab-ci tags for this runner (comma separated):opsdoc  Whether to run untagged builds [true/false]:[false]:true  #此处我选择的是true,不然每次push还得弄tag Whether to lock Runner to current project [true/false]:[false]: Registering runner... succeeded

然后根据提示信息输入,具体的token和url在项目的Settings-->CI/CD Pipelines下。 然后你就会在上图页面看到你增加的runner了。记得要Whether to run untagged builds [true/false]:选择true,不然触发时会卡住~ 理论上建立完毕之后就会部署一次,可在项目路径下Pipelines--->Pipelines里面查看部署过程。


0