43
头图

image.png

What is front-end automation

Front-end automation does not mean automatically generating code, but automatically building projects.

If there is no automation, our front-end work flow from development to testing may be as follows:
1. Write code on the local machine
2. Enter npm run unit/lint on the command line to view the unit test/eslint verification results
3. Submit the code, push to the git remote warehouse
4. Execute npm run build to build the project
5. Various methods such as ssh/ftp sending packages to the test server
In this process, each step has to be repeated manual operations, which greatly increases the time cost and cannot guarantee the accuracy of the operation. For the result of unit or build, there is no automatic feedback mechanism. It is necessary to manually check the running result. The final deployment is also to manually log in to the server to execute the script, which is very cumbersome.

introduces automation, the whole process becomes:
1. Write code on the local machine
2. Submit the code, push to the git remote warehouse
3.Git hook triggers the construction of jenkins job
4. Pull the project code from jenkins job, run npm run unit/lint and npm run build.
5. Execute the deployment script of the test server in jenkins job
In the automated process, only step 1 and step 2 require manual operation, and other steps are automatically run. It is a very standardized process, which reduces the risk of manual operation, eliminates repetitive work, and enhances the visibility of the project.

Effect picture

fomAnf.gif

accomplish

flow chart

image.png

  • Developers submit code to the code base
  • Trigger jenki build task
  • The build is successful, the package is sent to the nginx server, and the update is complete
  • Build failure, remind developers of code build failure through DingTalk notification/Enterprise WeChat/Email, etc.

1. Preparation:

Prepare git project: https://github.com/wzc570738205/frontproject.git
Prepare group (used to receive CI/CD result notification): 35669766
Ready to install the cloud server here, refer to on the linux server

2. Notification of access code submission

When you push the code to the code base, automatically send a message to Dingding through the git webhook

2.1 Add Dingding Group Robot (Smart Group Assistant)

image.png
Copy webhook, you will use it next
image.png

2.2 Add Dingding webhook to the corresponding webhook corresponding to github

image.png

2.3 Notification of test code submission

Configuration is complete, we submit the code for testing
image.png
far, the code submission notification configuration is complete

3. Access project CI

After we submit the code, we need to verify that there are no fatal errors in the code merge. Here we take a simple method to allow npm run build . If there is no error in the operation, then the submission is passed. Failure means that the code has a fatal error and needs to be modified

3.1 Jenkins new project

Here are brief steps. For details, please refer to Use Jenkins to automatically build a github project

  • Create a build a free-style software project
  • The source code manager selects git, and fills in the address and credentials (create a new one if not)
  • Build trigger selection: GitHub hook trigger for GITScm polling
    image.png
  • Add node environment: system management/global tool configuration-add nodejs, select the appropriate version
    image.png
  • Select node for the build environment, check the node just downloaded
  • Build selection execute the shell:

    npm install -g cnpm --registry=https://registry.npm.taobao.org&&
    cnpm install&&
    npm run build

    image.png

  • Post-build operation (optional):
    image.png

We use the jenkins job to determine whether the CI is successful

3.1.1 Test

Submit the code again and successfully trigger the jenkins job
image.png
Successfully built
image.png

3.2 Access to build status notifications

  • Configure Dingding custom robot, and select security settings custom keywords, here you can #
    image.png
  • Download the jenkins plugin DingTalk for notification
    image.png
  • Configure plug-in=>System management select Dingding, fill in the custom robot webhook address just now
    image.png
    image.png
  • Turn on robot notifications in the project
    image.png
  • Click to start building and test

    image.png
    Wait for CI to end
    image.png
    Failure reminder
    image.png

far, the CI configuration is over, we have implemented the code submission nail reminder, and the CI notification reminder

4. Access CD

In the above steps, we implemented the CI operation, that is, whether the package of the generation environment can be packaged to suggest whether the code has fatal errors. After this step is passed, we need to send the deployment package to the nginx server

4.1 Send package to server

  • Install the jenkins plugin Publish Over SSH
  • Configure the plug-in in the settings, fill in the server ip, use the password in the advanced, and set the remote server folder /
    image.png
    Click to test connectivity
    image.png
  • Project configuration
  • Modify the build shell, add compression

    npm install -g cnpm --registry=https://registry.npm.taobao.org&&
    cnpm install&&
    rm -rf dist&&
    npm run build&&
    cd ./dist&&
    tar -zcvf dist.tar.gz *
  • Add post-build operation Send build artifacts over SSH
    image.png
  • Server configuration nginx

    location /testPage{
     alias     /home/test;
     index     index.html;
    }

Test, after the build is successful, visit https://wangzc.wang/testPage
At this point, the CD integration is complete, and now you only need to submit the code to realize automatic packaging and automatic deployment.

Concluding remarks

I will continue to write how to access gitee, gitlab, and svn in the future.

WX20210922-091703.png


雾岛听风
11.9k 声望8.6k 粉丝

丰富自己,胜过取悦别人。