travis CI

travis可對多語言持續繼承,本文以nodejs 爲例。 首先添加文件.travis.yml 中
language: node_js
node_js:
  - "6"
  - "6.1"
  - "5.11"
  - "0.6"
  - "iojs"
版本具體的用法
● node latest stable Node.js release
● iojs latest stable io.js release
● 6 latest 6.x releasenode

在項目配置文件package.json中,添加測試腳本,因爲我用的是mocha,所以添加git

"scripts": {
"test": "mocha"
},
github

若是想讓每次提交git的時候,觸發持續集成,添加如下
"repository": {
"type": "git",
"url": "https://github.com/ryansecret/mytest.git"
}web

能夠看到,type:git,一樣能夠添加其它版本工具。
配置完成後,提交到git。在travis中可看到,build的全部過程:npm

如上:是否是很清晰。
travis的構建主要分兩大步驟:1 安裝全部依賴項 2 運行script 中定義的腳本,如test等。還能夠添加一些具體步驟,其實一個完整build由如下構成:
1. Install apt addons
2. before_install
3. install
4. before_script
5. script
6. after_success or after_failure
7. OPTIONAL before_deploy
8. OPTIONAL deploy
9. OPTIONAL after_deploy
10. after_scriptjson

   

須要注意的是before_install, install or before_script 中只要任何一個失敗,整個構建就是失敗。api

install:
- wget https://protobuf.googlecode.com/files/protobuf-2.4.1.tar.gz
- tar -xzvf protobuf-2.4.1.tar.gz
- pushd protobuf-2.4.1 && ./configure --prefix=/usr && make && sudo make install && popd
能夠編寫本身的腳本,例如在travis.yml中添加:
install: ./install-dependencies.sh
若是分爲多個執行,用法以下:
install:
- bundle install --path vendor/bundle
- npm install服務器

也能夠跳過安裝腳本:install: truedom


能夠指定編譯的git分支:
# blocklist
branches:
except:
- legacy
- experimentalide

# safelist
branches:
only:
- master
- stable
分支匹配能夠使用正則:
branches:
only:
- master
- /^deploy-.*$/
若是這次提交不想構建的話,那麼在提交信息中添加:[skip ci]。

自定義host,構造的時候會在/etc/hosts中添加
addons:
hosts:
- travis.dev
- joshkalderimis.com

構建成功後就能夠部署了,支持腳本部署:
deploy:
provider: script
script: scripts/deploy.sh
on:
branch: develop
腳本中能夠是個請求,重啓各個服務器上的服務。
一樣能夠發佈到npm上,
deploy:
 provider: npm
 email: "YOUR_EMAIL_ADDRESS"
 api_key: "YOUR_API_KEY"

設置只有打tag的時候進行部署:
deploy:
...
on:
tags: true


當編譯成功或失敗時,可設置一個通知:
notifications:
email:
recipients:
- one@example.com
- other@example.com
on_success: [always|never|change] # default: change
on_failure: [always|never|change] # default: always
注意的是上面email的地址是在github上註冊過的,不然是收不到消息的。對主要的團隊協做平臺都有支持,如slack、HipChat 等。
同時還能夠設置webhook通知:

 

notifications: webhooks: urls: - http://hooks.mydomain.com/travisci - http://hooks.mydomain.com/events on_success: [always|never|change] # default: always on_failure: [always|never|change] # default: always on_start: [always|never|change] # default: never

相關文章
相關標籤/搜索