What is CI/CD?

CI (Continuous delivery) automatically builds, packages, validates code formats, runs tests, and tests coverage after functional iterations, most commonly Webpack, Rollup, ESLint, etc.

CD (continuous deployment) is where code is automatically deployed to the server after CI.

Deploy CI, CD in GitLab

GitLab CI/CD is deployed using the. GitLab -ci.yml configuration file.

cd project_path

touch .gitlab-ci.yml
Copy the code

Create a simple CI/CD configuration:

Image: node:latest Install -job: stage: install only: stage: stage: install only: stage: stage: install only: -npm I # build-job # build-job # build-job # build-job # build-job Stage: build only: -master-develop-master script: -npm run build # Upload to the server deploy-job: stage: deploy only: - master - develop - master script: - npm run deployCopy the code

. Gitlab-ci. yml Common configuration:

configuration instructions
image The mirror
jobs As shown above:install-job,build-jobIt’s Jobs, it’s.gitlab-ci.ymlThe basic elements.
stages Used to combine jobs to work in steps that correspond to subsets of stages and stages under jobs.
only Specifies the execution scenario for jobs. The corresponding scenario is except.

What is the CLI

CLI (Command line interface) is similar to CI in that it eliminates repetitive work, such as vue-CLI for initializing projects, creation-React-app, and Aliyunoss-CLI for uploading static resources to Aliyun.

Use aliyunoss-cli to automatically upload aliyunoss

Download and install the CLI:

NPM install aliyunoss-cli --save-dev NPX aliyunoss-cli --version 1.1.1Copy the code

Create the configuration file alioss.config.json:

{
  "region": "-",
  "accessKeyId": "-",
  "accessKeySecret": "-",
  "bucket": "-"
}
Copy the code

Add the OSS paths corresponding to each environment to the configuration file:

{
  "region": "-",
  "accessKeyId": "-",
  "accessKeySecret": "-",
  "bucket": "-",
  "releaseEnvConf": {
    "dev": {
      "source": "dist/",
      "target": "home/dev/"
    },
    "pre": {
      "source": "dist/",
      "target": "home/pre/"
    },
    "prd": {
      "source": "dist/",
      "target": "home/prd/"
    }
  }
}
Copy the code

To issue an order:

NPX aliyunoss-cli --releaseEnv dev -- pre-release NPX aliyunoss-cli --releaseEnv pre -- produce NPX aliyunoss-cli --releaseEnv PRDCopy the code

Specify the path directly using the command line concatenation argument:

NPX aliyunoss-cli --source dist/ --target home/devCopy the code

Add script to the.gitlab-ci.yml command line:

"deploy": "aliyunoss-cli --releaseEnv dev",
"publish": "npm i && npm run build && npm run deploy"
Copy the code

Copyright statement

All the original articles in this blog are reserved by the author. Reprint must contain this statement, keep this article complete, and in the form of hyperlink to indicate the author and the original address of this article: blog.mazey.net/1695.html