Write in front
Initial contact with the continuous integration automation process. This article mainly introduces the method of achieving continuous integration based on Jenkins, and introduces the configuration process of online automatic compilation and deployment through cases.
Continuous integration
Continuous integration is a software development practice where team development members often integrate their work, through each member at least once a day, which means that multiple integrations may occur every day. Each integration is verified through automated construction (including compilation, release, automated testing), so that integration errors can be detected as early as possible.
Jenkins
Jenkins is a continuous integration tool developed based on Java to monitor continuous repetitive work, and its functions include:
1. Continuous software version release/testing projects.
2. Monitor the work executed by external calls.
For more information, please click the official website
Install
There are many Jenkins installation and configuration tutorials online. For details, please click on the Jenkins installation and configuration.
background
Jenkins runs on a Linux server and tries to compile and deploy a web application on this server. The compilation process requires a node environment. After compilation, the file needs to be sshed to the test server.
Jenkins' main tasks are as follows: 1. Automatically integrate the compilation environment 2. Online compilation of applications 3. SSH to the target environment and run
Create a new job
Log in to Jenkins and you can see the current construction status of all integrated projects;
1. Click [New] in the upper left corner to create a new task
2. Fill in the task name, and the type of project you build can be selected according to the actual situation. You can choose the first one this time.
3. After the selection is completed, click [OK] and return to the homepage. I found that the created job has been displayed in the list.
Configure the compilation environment
In this process, we need to configure a node-based compilation environment for the application.
Regarding the installation of node, you can generally download the execution file to install or compile the source code to install it. Through Jenkins, we can consider using the plug-ins it provides for automatic installation.
1. Select System Management->Management Plug-in
2. You can see that Jenkins provides a wealth of plug-ins for developers to use. Find the [NodeJS Plugin] we need, and then click to install it.
3. After the installation is completed, select System Management->Global Tool Configuration to configure node download and installation
4. After entering, go to the bottom and find that NodeJS configuration items have appeared in the globally available tools. 5. The plug-in supports multiple ways to install nodeJS. Click [New Install] and select the customary installation method. Here is the configuration downloaded and installed from the node official website.
6. After saving, go to the newly created job through the list, find [Build Environment], check Provide Node & npm bin/ folder to PATH, and select the configuration you just added; after each build, the environment construction will be performed first. Only after the environment is built correctly will the real construction process begin.
Configuration build process
In this process, we can configure the parameters required for the build to indicate where the build is (from which branch/which version...) or some other state; and execute the build through commands.
1. Enter the Job details through the list and start the relevant configuration;
2. The [General] column requires the configuration of basic project information and some parameters required for construction. Select [Parameterized build], which allows us to customize the parameters during the build process. As follows: Configure a branch parameter to indicate the git branch to be built
3. The [Source Code Management] column requires filling in the source code address of the project to be built, where [Branches to build] is used to indicate the branch to be built. Of course, you can also select a certain submission number. At the same time, we can also use the variables we define in General here (see the [Help] button on the right side of the input box for details)
4. The [Build] column requires inputting relevant commands to implement automated construction. After this process is [Environment Construction], we can write the following code to execute the construction.
5. After the online compilation is completed, the file completed by the build is sent to the target environment (test environment/production environment). Continue to add configuration in the [Build] column to specify the target environment related information; some operations after ssh are configured in the command line (decompress the file and delete the compressed package)
Execute the build
At this point, the configuration of the entire build has been basically completed, so the construction will begin. Go back to the list page and click Build:
You can see that the current build progress is displayed in the build history list
Click the round button on the left to enter the console to view the output
After the build is completed, you can view the build results through the rainy state in the list.
Conclusion
This article briefly introduces the process of building based on Jenkins. There are many Jenkins functions, which will be introduced in the following article. As the scale and complexity of project development continue to increase, continuous integration is an inevitable choice.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.