Foreword
If you manually deployed the project, we will be deeply necessity of continuous integration, because it is manual deployment and time-consuming and cumbersome, although the deployment process basically fixed, still prone to error.
If you are familiar with continuous integration, we will agree with this view: "It has become a standard to use."
What is continuous integration
the Continuous Integration (CI) IS A Development Practice The requires that Developers to integrate code INTO A Shared Repository 'several' Times A Day. Each the Check-in Verified by the then IS AN Automated Build, Allowing Teams is to Detect Problems Early.
--- ThoughtWorks
translation: continuous integration is a development activity, it requires developers to integrate the code multiple times a day to a shared repository, each submission will be checked automatically builds, teams can therefore detect problems in advance.
Continuous integration tool is very large, for example with java language development Jenkins, due to its characteristics can be distributed build and load testing on multiple machines, many large companies are using it.
But Jenkins' without modification interface interface so I have some dislike ...
With the development of GitHub, there has been growing support for GitHub of CI / CD products. On GitHub market, we can see that already supports continuous integration service provider has more than more than 300 ( more details ).
Choose Travis CI, is recommended because a lot of friends around.
Here I share with you how to use the Travis CI + GitHub achieve continuous integration and automated deployment through some of my research and practical experience, the desire to help a friend in need.
What is Travis CI
Travis CI is a continuous integration services with an open source Ruby language development of distributed, used to automatically build and test project hosted on GitHub. Including support Javascript, Node.js, Ruby and other 20 kinds of programming languages. For open source projects with free CI services. You can also buy his paid version, enjoy more services.
Travis CI currently has two official website, are https://travis-ci.org and https://travis-ci.com.
https://travis-ci.org old platform to the new platform has been gradually migrated https://travis-ci.com. For private warehouse of free automated build, Travis CI on the new platform has supported.
First, access to GitHub Access Token
Travis CI when the automatic deployment of the need to push the contents of a branch warehouses, and access GitHub repository require user authorization, authorized way to provide users with Access Token to Travis CI.
Get token GitHub->Settings->Developer Settings->Personal access tokens
position: .
Check repo
all the items, and user
under the user:email
rear, generates a token, token value replication.
Note: This token is only now can see, will not see re-enter, but never see, forget it can only regenerate, so remember to take good care of.
Second, the use GitHub account login Travis
Enter Travis's official website , log in with GitHub account. (I am currently using its old platform)
After logging in, you will see all public open source repo under their own account in GitHub Travis Lane.
Third, open the monitoring of projects
Selecting a target item, the right switch is opened.
Fourth, configure travis
- Click the switch on the right Settings, enter travis configuration page of the project
- Check the trigger condition
- Set global variables
Note: The first step in obtaining the access token, you must set
-set variables can be $ {name} variable to reference in the configuration file.
Fifth, add the project root directory .travis.yml
profile
Note that the file name to
.
begin with.
Travis CI once constructed in two steps:
- install, the installation of any required dependencies
- The script is run build scripts
Travis CI offers some build lifecycle "hook"
Travis CI build a complete life cycle:
- OPTIONAL Install
apt addons
- OPTIONAL Install
cache components
before_install
install
before_script
script
- OPTIONAL
before_cache
(for cleaning up cache) after_success
orafter_failure
- OPTIONAL
before_deploy
- OPTIONAL
deploy
- OPTIONAL
after_deploy
after_script
In before_install
, before_script
before, or after_script
after, you can run custom commands while the details may refer to the official documentation: the Job Lifecycle
I footprint
project .travis.yml
a complete configuration:
language: node_js #设置语言
node_js: "10.16.3" #设置语言版本
cache:
directories:
- node_modules #缓存依赖
# S: Build Lifecycle
install:
- npm i
script:
- npm run build
#after_script前5句是把部署分支的.git文件夹保护起来,用于保留历史部署的commit日志,否则部署分支永远只有一条commit记录。
#命令里面的变量都是在Travis CI里配置过的。
after_script:
- git clone https://${GH_REF} .temp
- cd .temp
- git checkout gh-pages
- cd ../
- mv .temp/.git dist
- cd dist
- git config user.name "${U_NAME}"
- git config user.email "${U_EMAIL}"
- git add .
- git commit -m ":construction_worker:- Build & Deploy by Travis CI"
- git push --force --quiet "https://${Travis_Token}@${GH_REF}" gh-pages:${D_BRANCH}
# E: Build LifeCycle
# 只有指定的分支提交时才会运行脚本
branches:
only:
- master
Done!
The .travis.yml
push to the remote, you can see travis start building a compiler. And after each push of code, travis automatically execute .travis.yml
script in the configuration of the task.
- Automatic compilation:
- Building completion, travis based on my configuration, automatically deployed to GitHub:
And One More Thing
After building a successful, we can add in your own GitHub project in the build
badge.
Methods: Travis, click on the badge on the right side of the project, you can get a small badge address, the address in README.md document can be.
effect:
--
GOODLUCK!
Welcome to reprint, please indicate the source: https: //champyin.com/2019/09/27/%E5%88%A9%E7%94%A8Travis-CI-GitHub%E5%AE%9E%E7%8E% B0% E6% 8C% 81% E7% BB% AD% E9% 9B% 86% E6% 88% 90% E5% 92% 8C% E8% 87% AA% E5% 8A% A8% E9% 83% A8% E7% BD% B2 / # more
This article was published in sync:
the use of Travis CI + GitHub achieve continuous integration and deployment of automatic | Denver