部署github

参考使用hexo将博客部署到github

部署gitlab

注册gitlab账号

  • 登陆gitlab官网、注册账号并通过邮箱验证。

  • 信用卡验证(使用visa或者master信用卡)

建立博客仓库

  • 点击Creat blank projectCreate new project

  • 建立username.gitlab.io的仓库名称(username为用户名),如下设置:

切记不要初始化

本地git连接gitlab

参考Mac同时配置github、coding和gitlab的SSH公钥

修改配置文件_config.yml

修改方法如下:

1
2
3
4
5
6
7
8
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repository:
github: git@github.com:username/username.github.io.git
gitlab: git@gitlab.com:username/username.gitlab.io.git
branch: master

username为name of gitlab and github

上传内容

1
2
3
4
cd myblog
hexo clean
hexo g
hexo d

添加CI/CD

添加内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
# This file is a template, and might need editing before it works on your project.
# Full project: https://gitlab.com/pages/plain-html
pages:
stage: deploy
script:
- mkdir .public
- cp -r * .public
- mv .public public
artifacts:
paths:
- public
only:
- master

Pipelines中任务显示任务为passed则成功

修改master为unprotect

访问网站

访问usernamne.gitlab.io
usernamne.github.io

本文更新于2021.5.27