github
帐号一个vue
的项目linux
服务器travis
是基于github
的,全部只有github
的帐号能够登陆travis
,开发者必须有一个github
的帐号,登陆后,点击加号,开始添加项目html
点击Manage repositories on GitHub
,前往github中选择项目vue
这里github提供的两种模式,第一种添加全部项目,第二种添加指定项目,通常咱们选择第二种添加须要添加的项目node
在github
的我的中心,https://github.com/settings/tokens/
路径下,生成一个访问令牌,添加到travis中,给travis操做仓库的权限linux
复制令牌内容,进入travis
中的中,找到SSH key的菜单,将令牌内容贴入,点击Add
git
在项目根目录下,新建.travis.yml
文件。travis要执行的自动化步骤,都须要在该文件中配置,这里是一个最简单的配置文件,当travis检测到master分支代码发生变化时,自动执行npm install和npm run buildgithub
language: node_js node_js: - 10.16.0 cache: directories: - node_modules install: - npm install before_script: script: - npm run build after_script: branches: only: - master
关于travis
的更多配置,参考阮老师的教程:npm
http://www.ruanyifeng.com/blo...
开发者在本地执行npm run build,编译后生成dist目录,服务器须要的也是dist目录。travis要作的就是把dist目录自动发送到服务器服务器
先说思路,当travis执行build生成目标文件后,travis把dist目录提交到仓库的指定分支,好比叫deploy分支,经过ssh自动登陆服务器,执行git pull,把deploy分支拉下来ssh
after_script: - cd ./dist - git init - git config user.name "your name" - git config user.email "your email" - git add . - git commit -m "Travis CI Auto Builder" - git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" master:deploy - ssh your-name@xx.xx.xx.xx 'cd /your-path && git fetch --all && git reset --hard origin/deploy && git pull'
配置文件上的操做执行成功后,你的项目就多了这个高大上的标志fetch
报错提示通常是这样的:
openssl aes-256-cbc -K $encrypted_d3c25c1810a6_key -iv $encrypted_d3c25c1810a6_iv -in id_rsa.enc -out ~\/.ssh/id_rsa -d ~/.ssh/id_rsa: No such file or directory The command "openssl aes-256-cbc -K $encrypted_d3c25c1810a6_key -iv $encrypted_d3c25c1810a6_iv -in id_rsa.enc -out ~\/.ssh/id_rsa -d" failed and exited with 1 during .
这个报错状况的出现,有多是由于在使用travis encrypt-file ~/.ssh/id_rsa --add
命令生成加密密钥时,自动增长了转义字符串,须要手动删除转义字符
生成的密钥是这样的:
- openssl aes-256-cbc -K $encrypted_d3c25c1810a6_key -iv $encrypted_d3c25c1810a6_iv -in id_rsa.enc -out ~\/.ssh/id_rsa -d
删除转义字符后是这样的:
- openssl aes-256-cbc -K $encrypted_d3c25c1810a6_key -iv $encrypted_d3c25c1810a6_iv -in id_rsa.enc -out ~/.ssh/id_rsa -d