background
Hello, I came back again, according to the last post has more than 70 days in the past, since dedicate my first time to the nuggets, only to find that there was a lot of people like so have the opportunity to also attend the annual general meeting, also get a plush toys, in order to be kept in this year’s conference, also can get a plush toys, I fart dian fart is back again, yes, I am so practical, so shameless
Problem analysis
Anyway, Jenkins is the subject of today’s talk. Any technology must have been developed to solve some or some problem. So before we talk about Jenkins, let’s first describe the problems we encounter.
The project is going online. What is the online process? Here is the simplest pure front-end project example, who let us is front-end development?
1. Develop branches to merge to master and switch branches to Master
2. Install the required dependent libraries, that is, NPM install
3. Build a package, also known as NPM run Build
4. Log in to the server and delete the program of the previous version
5. Throw the packaging result into the server Web container
All right, we’re online, and everything seems normal. All right, here we go, here we go…
PM came at this time: said there was a word written wrong, to quickly modify the line.
What!! At this point, although there are ten thousand grass mud horses in mind, but also have to revise the line later.
So after you change the word, you repeat the above five steps.
Let’s say that the project itself iterates quickly, and that each iteration is more than just five steps?
In fact, this is not an assumption, the fact is clearly much more complex than the above steps, especially back-end projects, especially complex interconnected interdependent large projects
So what to do? I can’t waste my time repeating myself. I have to learn new things. There’s a lot of performance to go around! I got a wife and kids waiting at home!
What I want is for the code to go live automatically as soon as it’s merged into the master
Huh? Who is calling me? Jenkins, who was brought in to solve the problem of continuous integration, continuous delivery, Use more professional words CI/CD, I’m an English lover
So how does Jenkins solve this problem?
First of all, our code generally has version control, code repository, whether it is GitLab or Github, they all have a thing called Webhook, which basically means that they can notify you whenever you have code submission, branch merge, etc. In this case, of course, Jenkins. Jenkins is going to be notified. You’re going to have to provide something, otherwise you’re not going to be notified. That’s right, Jenkins provides a Webhook URL, just fill it into the webhook configuration item in the repository
Jenkins receives Webhook from something like this: http://jenkins server /project/demo
Let’s say Jenkins gets A notification that someone has merged the code into the master for project A. Does Jenkins need to build at all? The Jenkins build trigger is a set of conditions that will trigger your build.
For project A to be rebuilt, Jenkins needs to know where the code in project A is, which is the address of your code repository. I need to have the right to clone your code, so Jenkins needs to know the account and password of your code repository. The last step is to prepare Jenkins for the build, but Jenkins needs to know exactly what you’re going to be doing. Yes, most of the time it’s executing shell command-line scripts.
Take the simplest pure front line example above:
// Pseudo shell scripts
CD to the project code directory
npm install
npm build
CD to the Web service directory
Rm dropped the last version of the project
Cp the newly built project to the Web services directory
//end
Summarize the main points of this section, that is, the keywords highlighted above
1, webhook
2. Build triggers
3. Code repository address
4. Account password
5. Shell command line script
After understanding why and how it works, here is how to use it (Jenkins installation is not described here, if necessary, you can search by yourself)
Step 1: Create a new task, enter a name, select the first item, and build a free-style software project
Second, enter the project description
Step 3: Enter the code’s warehouse address and inform Jenkins of the warehouse account and password
Step 4, set up the build trigger
Step 5, write the build command script
conclusion
I don’t know if you can make a simple statement about Jenkins at the end, but it’s not about me either
Epidemic prevention might as well learn, finally, I wish you good health during the epidemic!