之前通过Travis CI实现持续部署Hexo项目到腾讯云服务器。经过一段时间的使用,发现Travis CI传输文件到腾讯云服务器经常失败,所以打算在本地自建Jenkins,同时利用GitLab进行持续部署
实现步骤如下:
- 关闭
Travis CI触发器
- 导入
Hexo相关项目到GitLab
- 新建
Jenkins Freestyle工程
关闭Travis CI触发器
在Travis CI项目页面的Settings中关闭构建命令即可

导入Hexo相关工程到GitLab
将Hexo相关工程导入到本地GitLab,有助于加速Jenkins构建
新建Jenkins Freestyle工程
Jenkins安装和配置参考Jenkins使用指南
Jenkins中GitLab插件的配置以及GitLab Webhook的连接参考[Jenkins][Gitlab]webhook连接
新建Jenkins Freestyle工程hexo,进入配置页面,构建脚本如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| cd ./blogs/ git clone http://localhost:8800/zjzstu/hexo-theme-next.git themes/next git clone http://localhost:8800/zjzstu/theme-next-canvas-nest.git themes/next/source/lib/canvas-nest git clone http://localhost:8800/zjzstu/theme-next-algolia-instant-search.git themes/next/source/lib/algolia-instant-search git clone http://localhost:8800/zjzstu/theme-next-fancybox3.git themes/next/source/lib/fancybox npm install
rm node_modules/kramed/lib/rules/inline.js cp inline.js node_modules/kramed/lib/rules/ npm run gs hexo algolia
mkdir upload_git cd upload_git git init cp -r ../public/* ./ git add . git commit -m "Update blogs" git push --force git@148.70.xx.xx:/data/repositories/blogs.git master git push --force git@github.com:zjZSTU/zjzstu.github.io.git master git push --force git@git.dev.tencent.com:zjZSTU/zjZSTU.coding.me.git master
|
- 首先下载
GitLab中的项目
- 然后编译生成
html文件
- 最后上传到腾讯云服务器、
Gitlab和Coding