您当前的位置:首页 > 计算机 > 软件应用 > 开发工具(IDE)

Github travis ci 自动部署

时间:12-14来源:作者:点击数:
CDSY,CDSY.XYZ

1. ci 能干嘛

能在 push 代码的时候执行某些操作,同时可以通过指定一些参数,使得只在特定的 push,或者 commit message 时才会执行 ci job。

2. 配置示例

language: node_js
node_js:
    - 10
cache:
  directories:
    - "node_modules"
install:
    - npm i
script:
    - npm run build
after_success:
    - cd .docz/dist
    - git init
    - git config --global user.name "${U_NAME}"
    - git config --global user.email "${U_EMAIL}"
    - git add -A
    - git commit -m 'deploy'
    - git push --quiet --force "https://${GH_TOKEN}@${GH_REF}" master:${P_BRANCH}
branches:
  except:
    - master
branches:
  only:
  - gh-pages

分别是指定语言,指定 node 版本,指定缓存目录等,同时在 after_success 时,通过命令实现向某个特定 URL 和分支 push 代码。

  • GH_TOKEN:在 github 上 生成的 token(link:https://github.com/settings/tokens),我理解是只有携带该 token,travis 才能拥有权限执行 push 的操作(不确定新版本的 travis 是否还需要这样操作,好像可以直接操作 github)。
  • GH_REF:类似 github.com/[username]/[repository].git 的地址,无需 https 协议前缀
  • P_BRANCH:目标分支。

3. 遇到的问题

3.1 travis.org 与 travis.com 的区别

资料(link:https://devops.stackexchange.com/questions/1201/whats-the-difference-between-travis-ci-org-and-travis-ci-com),即原本 travis-ci.com 用于私人付费项目,travis-ci.org 用于公共免费项目。但18年5月之后都是推荐使用travis-ci.com(link:https://travis-ci.com/). 最近在部署 react-story-book 的时候,发现 travis-ci.com(link:https://travis-ci.com/) 加载不到我的react-story-book仓库,而 travis-ci.org(link:https://travis-ci.org/) 可以,因此又使用了travis-ci.org

3.2 报错 GitHub Pages branch not include ...

branches相关配置资料(link:https://docs.travis-ci.com/user/customizing-the-build#building-specific-branches),即默认 gh-pages 分支不会执行 ci job,除非手动添加到白名单。

branches:
  only:
  - gh-pages
CDSY,CDSY.XYZ
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门
本栏推荐