Factories have begun assembly line automation, what’s more, we walk in the forefront of technology? In this era of automation, or to automate to do things more reliable, on the one hand, accuracy can improve a lot, on the other hand, also improve work efficiency, save working time, give yourself more time to think about the depths of the hidden technology.
First of all, I would like to describe the usage scenario. I built the front-end automatic deployment environment according to some basic commands of the front-end, mainly using Docker+Jenkins+ Githook, githook is mainly to realize automatic compilation of the code. In fact, serious students will find that hook is also realized by the principle of Eventbus. But in actual use, we will find that every time to carry out NPM install, if the team small number, time, more projects, that is good, anyway don’t care about these, but if you do not have the above conditions, you will find in this step will waste a lot of time, you will after a long wait for process, You’ve probably played 2 games of King of Glory and got 2 quintuples.
At first, I saw that many people are implementing the public library, but I saw that the configuration of the construction is cumbersome, so directly give up, so the heart of evil thoughts: There is no easier way to do this, so start with the package.json file and check for changes in this file. If there are changes, it indicates that there are changes in dependencies. Then execute NPM install.
#!/bin/bash
timestamp=`date +%s`
filepath=./package.json
if [ -f $filepath ];
then
echo "Package. json file exists!
filetimestamp=`stat -c %Y $filepath`
lasttimestamp=`stat -c %z $filepath`
echo "Package. json file last modified: $lasttimestamp"
timecha=$[$timestamp - $filetimestamp]
if [ $timecha -gt 60]; then echo'The current time is greater than the last modification time of the file 60 seconds, do not execute install:'
npm run build:pro
else
echo 'The current time is less than 60 seconds since the file was last modified.
npm install &&
npm run build:pro
fi
else
echo "File does not exist or you entered the wrong path"
fi
Copy the code
Front-end Jenkins construction script needs to modify corresponding packaging commands according to different environments. Currently, Jenkins server is divided into three files for execution: Sh, run-test-install.sh, run-pro-install.sh, upload these three files to Jenkins server, and then configure them in Jenkins management interface. After testing, it is done