Travis配置
GItHub创建Access Token
登录GItHub–>GitHub用户头像–>Setting–>Developer settings–>Personal access tokens–>Generate new token
勾选repo
及user:email
点击创建。生成的token只显示一次,所以需要先保存起来后面会用到。
Travis CI配置
配置Travis公共仓库服务:travis-ci.org,配置Travis私有化仓库服务:travis-ci.com
这里我们使用公共仓库服务travis-ci.org
打开Travis CI网站,使用GItHub账号登录,点击Sync account
会显示GitHub项目列表。选择博客项目开启Travis支持。
点击项目找到More options
中的Setting
开启Build only if .travis.yml is present
和Build pushed branches
。
在Environment Variables
创建环境变量TravisCIToken
值为在GItHub创建的Access Token的token值。不要勾选Display value in build log
,否则会在日志文件中暴露 token
信息。
创建.travis.yml文件
注意yml文件中不能使用
tab
进行缩进,使用空格缩进,:
后有一个空格。
Hexo根目录blog文件夹内创建.travis.yml:
1 | anguage: node_js |
Hexo根目录blog文件夹内创建publish-to-gh-pages.sh:
1 |
|
自动部署
- 打开Git Bash
以下操作全部在Hexo根目录blog文件夹内执行
- 创建远程分支
1 | $ git checkout -b hexo |
- 初始化本地仓库:
删除原来部署时产生的.git文件夹(隐藏文件夹)
1 | $ git init |
- 关联远程仓库
1 | $ git remote add origin [email protected]: |
- 推送仓库
1 | $ git add . # 添加文件 |
推送成功后可以在travis-ci.org后台查看自动部署情况。