Some time ago I was looking at an automated deployment solution. I wrote a rough script for Node, but it wasn’t elegant enough, so I looked at Jenkins and found that the build cost was slightly higher (actually Jenkins was pretty sweet), and since I was considering the solution based on my own project, I decided to use Travis as the solution.
Travis
To use Travis, you first have to have a GitHub account and log on to the Travis website. Select the GitHub account to log in, as shown below:
Then import it into your warehouse and let Travis listen.
Go back to your project and create a.travis. Yml file. The repository that Travis listens to will execute the corresponding script in YML whenever push (default listening master branch).
YAML (YAML Ain’t a Markup Language)YAML is not a Markup Language. It is usually a file with a.yml suffix. It is an intuitive data serialization format that can be recognized by computers, and is easy for humans to read and interact with scripting languages. Can be imported by a different programming language program that supports the YAML library, a language specifically used for writing configuration files. Can be used for Java, C/C++, Ruby, Python, Perl, C#, PHP, etc.
Here’s a template:
In this case, we use nodeJS as the front end of the languagelanguageTravis will use NVM to manage the node versionnode_js:
- "14"# Specify branch (default: master)branchs: only: -master # install phase: install dependencies (this phase executes scripts in sequence and terminates if one step fails)install:
- npm install --registry=https://registry.npm.taobao.org
- echo "install successed"The # script field is used to specify a build or test script. (The script failed one step in this phase and will continue later, but the state of the entire build phase is failed; If you specify jobs, you can leave them here.script: -npm run build # Specifies the operating systemos: -Linux # This is equivalent to defining the order of workstages: -test-name: specifies the deploy # jobjobs: # Containsinclude: # Stage name -stage: test # Run scriptscript:
- node --version
- npm --version
- echo "Testing Started ..."
- npm test
- echo "Testing Finished."
- stage: deploy
script:
- echo "NPM Deploying Started ..."
- git clone https://${GH_REF}
- cd vue-dark-photo
- git branch
- git checkout travis
- git rebase master
- npm version patch
- npm install --registry=https://registry.npm.taobao.org
- npm run build
- echo "NPM Building Finished."This is the NPM package (for example), specify your email address (which will notify you), api_key (your NPM token, which is usually found in.npMRc, if you have logged in to NPM locally)deploy:
provider: npm
email: "${EMIAL}"
api_key: "$NPM_TOKEN"
skip_cleanup: true
on:
all_branches: trueExecute after the # script phaseafter_script:
- git config user.name "travis"
- git config user.email "${EMIAL}"
- git add .
- git commit -m "Travis CI Auto Builder"
- git status
- git push "https://${GH_TOKEN}@${GH_REF}" travis:travis
Copy the code
In some places, variables are used, which can be configured on the Travis website, as shown in the figure
Complete life cycle:
before_install
install
before_script
script
aftersuccess or afterfailure
[OPTIONAL] before_deploy
[OPTIONAL] deploy
[OPTIONAL] after_deploy
after_script
Copy the code
When the script is configured and you push it in the master branch of your project, Travis will listen to the change and query it.
You can also check it out on the Travis website, as shown here:
Matters needing attention
After associating Travis with the Git repository and configuring the YML file, I found that push didn’t work, but it worked again a day later (delayed?). , here still do not know what reason temporarily, have big guy know also please not stint grant instruction.