travis配置文件的编写

travis配置文件的编写

介绍

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
language: node_js
dist: trusty
sudo: required
matrix:
include:
- language: node_js
node_js:
- 8.15.0
env:
- TRAVIS_SECURE_ENV_VARS=false
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- mysql-5.7-trusty
packages:
branches:
only:
- master
- dev
before_install:
- echo -e "machine github.com\n login $CI_USER_TOKEN\n password x-oauth-basic" >> ~/.netrc
# Repo for Yarn
- sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
- echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
- sudo apt-get update -qq
- sudo apt-get install -y -qq yarn=1.12.3-1
script:
- node -v
- yarn -v
- ./travis-script.sh
cache:
yarn: true
directories:
- $TRAVIS_BUILD_DIR/project-template/client/node_modules

sudo

需不需要sudo权限 一般是要的require

matrix

相当于就是一个几乘几的各种情况, 自动给你跑, 也可以include, 也可以exclude下.

exclude的要精确匹配 env 这种

addons

额外的软件包

env

就是环境咯, TRAVIS_SECURE_ENV_VARS=false不加密

branch

要进行CI的分支, 可以写safelistonly和blocklistexcept

before_install

第一条命令: echo -e "machine github.com\n login $CI_USER_TOKEN" > ~/.netrc, 用来将登陆配置信息追加写入~/.netrc中, 方便以后登录不用填用户名密码.
travis API Token machine github.com\n

第二条命令: apt-key adv --fetch-keys will only fetch one key from the URL, and if the URL contains multiple keys, please use wget | apt-key add instead.

第三条命令: tee用来从标准输入中读, 然后便准输出. 就是一个复制粘贴的功能. 所以后面就是将 deb http://dl.yarnpkg.com/debian/ stable main 写入 yarn.list

第四第五条命令: 就是更新软件库表, 然后安装上 yarn

整个第2-5条命令就是在安装yarn https://yarnpkg.com/en/docs/install#debian-stable

script

就是这个travis要跑的脚本.

cache

就是cache, 看教程就是这么写的, $TRAVIS_BUILD_DIR就是当前.travis.yml所在的目录.

参考

持续集成服务 Travis CI 教程 阮一峰 666

Building a JavaScript and Node.js project

travis API Token machine github.com\n
.netrc文件简单使用
使用auth-source库读取Netrc文件中的用户名和密码
linux >和>>的区别

apt-get 命令详解(中文),以及实例
https://yarnpkg.com/en/docs/install#debian-stable