持續整合(CI)是一種軟體開發實踐,即團隊開發成員經常整合他們的工作,通過每個成員每天至少整合一次,也就意味著每天可能會發生多次整合。每次整合都通過自動化的構建(包括編譯,釋出,自動化測試)來驗證,從而儘早地發現整合錯誤。
Travis CI是在軟體開發領域中的一個線上的,分散式的持續整合服務,用來構建及測試在GitHub託管的程式碼。這個軟體的程式碼同時也是開源的,可以在GitHub上下載到,儘管開發者當前並不推薦在閉源專案中單獨使用它。
構建流程
本地寫完文章 => push github => GitHub觸發Travis CI構建 => 執行命令 => 部署 => 完成。
用github登陸travis-ci
travis-ci.com然後新增到你要啟用的儲存庫。


然後生成github和coding的Token。 先生成github的Token。 github.com/settings/to… 點選Generate new token。



點選新建令牌。


登陸travis-ci把github和coding的Token複製到環境變數。 travis-ci.com/


在專案根目錄新建.travis.yml 檔案
language: node_js
node_js:
- 8.9.0
cache:
directories:
- node_modules
before_install:
- npm install hexo-cli -g
install:
- npm install
script:
- hexo clean
- hexo generate
after_script:
- cd ./public
- git init
- git config user.name "github使用者名稱"
- git config user.email "github郵箱"
- git add .
- git commit -m "TravisCI 自動部署"
# Github Pages
- git push --force --quiet "https://${CI_TOKEN}@${GH_REF}" master:master
# Coding Pages
- git push --force --quiet "https://coding使用者名稱:${CO_TOKEN}@${CO_REF}" master:master
branches:
only:
- indigo 這裡替換你要監聽的分支
env:
global:
# Github Pages
- GH_REF: github.com/lanpangzhi/lanpangzhi.github.io 這裡替換你的github倉庫地址
# Coding Pages
- CO_REF: git.coding.net/bule/bule.coding.me.git 這裡替換你的coding倉庫地址
複製程式碼
然後提交github,travis-ci就會自動構建了。 現在寫部落格只需要兩步操作,第一步 hexo new "新的文章",第二步提交到github。travis-ci會幫你自動部署的。 省去了 hexo clean hexo g -d 的環節。
看到這張圖就代表成功了。

如果使用git子模組的話請使用https地址,或者在.travis.yml檔案禁用子模組,否則構建會報錯,提示沒有許可權。
我的部落格和github,喜歡就去點點星吧,謝謝。
參考
docs.travis-ci.com/user/for-be… zh.wikipedia.org/wiki/Travis… baike.baidu.com/item/%E6%8C… blog.csdn.net/qinyuanpei/…