In the case of separation of front and back ends, the front-end static code needs to be independently deployed to the server, where automation is needed to improve development efficiency

1. Environment construction

1)Install the VMware VM

Baidu cloud: link: https://pan.baidu.com/s/1IF6GdhQnmDc8wR3NjSf0iQ extracted code: 1 jukCopy the code

2)Unbuntu system

Download address: http://releases.ubuntu.com/20.04.2.0/ubuntu-20.04.2.0-desktop-amd64.iso torrent: http://releases.ubuntu.com/20.04.2.0/ubuntu-20.04.2.0-desktop-amd64.iso.torrentCopy the code

3)Jenkins software installation

Java SKD download: https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html JenKins download: https://pkg.jenkins.io/debian-stable/Copy the code

2. Configure a project

1) Create a task

1: Create a new item and name it my-Test. 2: Select the first option and freeStyle Project 3: Click OKCopy the code

2) Add build parameters

1: 2. Fill in some descriptions to explain the use of the modification project: Front-end automation deployment Case 3: Click this Project is parameterized to define some parameters that you can use to do extra processing when executing your shell scriptCopy the code

3) Get the Git branch

Git Parameter = 'Git Parameter' Variable name: branch, Description: branch (default: origin/dev) Parameter type: branch Default: origin/devCopy the code

4) Add drop-down selection parameters

1: Click 'Add Parameter' 2: Select 'Choice Parameter' 3: Fill in the configuration, which represents the dropdown selection box, and Jenkins can get the value of the selection box and access the variable with $buildScript: buildScript option: NPM run build:test NPM run build:dev NPM run build:prodCopy the code

5) Add a single box parameter

1: Click 'Add Parameter' 2: Select 'Boolean Parameter' 3: If you need to installDependencies again, you need to set the dependencies to "installDependencies". If you need to installDependencies again, you need to install "installDependencies"Copy the code

6) Add source management address

2. Select the Git address where the project code is stored, enter the username and password for verification. 3Copy the code

7) Install git submission record plug-in

1: Select 'Add Changelog Information to Environment' 2: Entry Format: %3$S (at %4$S via %1$s)\n Date Format: YYYY-MM-DD HH: MM: SS Note: This option is Jenkins plug-in, need to find a plug-in installation, said at the time of build automation, packaging, display submitted records (commit log) 2: the plug-in download address: https://github.com/KrisMarko/kr-changelog three: Install the changelog-environment.hpi plugin in JenkinsCopy the code

8) Write shell scripts

1: click 'add build step' 2: select 'Execute Shell' 3: Configure the shell script to be executed Note: At this point, the configuration is complete. When you pull git code, the contents of the shell script are executedCopy the code

9) Start building

1: Go back to the project and click 'Build with Parameters' 2: You can see the configuration of the Parameters 1: origin/dev 2: the Build script executed (NPM run Build :test) 3: Reinstall dependencies (False) 3: Click to start buildingCopy the code

This is mainly shell script execution. Copy the packaged static resources to the specified server and you can build it successfully

Qq discussion group: 475870039