Open whatwewant opened 6 years ago
jobs:
- stage: test
script: echo "script"
- stage: build
script: echo "build"
- stage: deploy
script: echo "deploy"
- stage: build
script: echo "build parallel"
// 执行顺序 test > build = build > deploy,也就是说test 先执行完毕,然后执行build,最后执行deploy,但是两个build是并行执行的
jobs:
include:
- stage: deploy
script:
- echo "build for deploy"
- npm run build
deploy:
# deploy to gh-pages
- provider: script
skip_cleanup: true
script: bash deploy.sh
on:
tags: true
# deploy to npm === npm publish
- provider: npm
skip_cleanup: true
api_key: $NPM_API_KEY
on:
tags: true
#!/bin/bash
echo "deploy to gh-pages."
rm -rf gh-pages/*
cp -rf dist/* gh-pages
cp CNAME gh-pages
cd gh-pages
git add --all .
git commit -a -m ":sparkles:(TravisCI) automatically update from travis_ci (version: $TRAVIS_TAG)"
git push --quiet "https://${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git" gh-pages:gh-pages
jobs:
include:
- stage: deploy
before_script:
- echo "before script"
script:
- echo "build for deploy"
- npm run build
after_success:
- echo "after script success"
deploy:
# deploy to gh-pages
- provider: script
skip_cleanup: true
script: bash script/deploy.sh
on:
tags: true
apt addons
(可选): 用于更新linux apt source,可自定义sources;cache components
(可选): 用于缓存组件(yarn)、文件夹(node_modules)等;before_install
: 用于安装外部依赖包(dependencies),比如ubuntu packages或者自定义服务;install
: 执行依赖安装(install any dependencies required),比如npm install 或者 ./install-dependencies.sh;before_script
script
: 执行构建脚本(run the build script);before_cache
(可选): 用于清空缓存;after_success
或者 after_failure
: 当script运行完后,after_success可用于构建文档或者部署服务等, after_faiilure可用于上传日志等;before_deploy
(可选)deploy
(可选): after_success运行结束后,执行部署服务,比如构建文档、构建gh_pages、发布npm包、部署heroku等;after_deploy
(可选)after_script
cache
skip_cleanup
tags
# 1 cache应用 - 缓存node_modules
# 2 skip_cleanup应用 - 保持之前脚本执行环境,默认为false; 当skip_cleanup为false时,Travis CI会清空之前脚本执行结果
# 3 tags应用 - 当on中tags为true时,只允许git tag版本执行部署(deploy)
cache:
directories:
- "node_modules"
script: npm test
before_deploy: npm install now --no-save
deploy:
- provider: script
script: now --token $NOW_TOKEN && now alias --token $NOW_TOKEN
skip_cleanup: true
on:
tags: true
格式很自由,但是一下是我比较喜欢的方式(.travis.yml)