Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Developers learn Linux (11): CentOS7 installation and configuration continuous integration tool Jenkins

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

1. Preface

In the previous article on how to install and use the code quality management platform SonarQube6.4 in CentOS7, in the previous article mentioned that SonarQube supports a variety of ways to analyze code quality, one of which is to automate code quality analysis in continuous integration tools. This article continues the previous article on how to install and use Jenkins. The predecessor of Jenkins is Hudson. At the time of writing, the latest version of Jenkins is 2.84.

two。 Prepare for

Software preparation:

Jenkins.war:Jenkins deployment file, download address: http://mirrors.jenkins.io/war/2.84/jenkins.war

Microsoft Build Tools 2015: without installing VisualStudio, you can use MSBuild to compile project files or solution files created by VisualStudio without installing this software. Download address: https://www.microsoft.com/en-us/download/details.aspx?id=48159

3. Installation

Since the war file is downloaded directly, you don't need to compile it, just put it under the Web container of Java. Because Tomcat8.5 has been installed and configured in this series, and the working path of Tomcat is: / usr/local/apache-tomcat-8.5.15/, so jenkins.war is placed in the / usr/local/apache-tomcat-8.5.15/ folder, and then access it in the browser.

My CentOS7 virtual machine IP is 192.168.60.198, so it can be accessed externally through the URL http://192.168.60.198/jenkins/. Here is the access interface:

Open / root/.jenkins/secrets/initialAdminPassword to copy the contents of the file into the text box and continue, as shown in the following figure:

Choose to install the recommended plug-in here, as shown in the following figure:

The installation process depends on the network, and I feel that the weekend time in the United States will be faster, while the download speed during the daytime on weekdays in the United States is very slow.

It is recommended that after the plug-in installation is complete, the interface for creating an administrator appears, as shown in the following figure:

Enter the account information to complete the installation of Jenkins and the settings of the first administrator.

Note: click the "Continue as admin" link to skip the administrator settings, the administrator account is "admin", and the administrator password is / root/.jenkins/secrets/initialAdminPassword; click "Saveand Finish" to save the contents filled in the current page.

4. Configuration 4.1 plug-in configuration

Jenkins provides a considerable number of plug-ins to support a variety of complex scenarios. Installed and installable plug-ins can be seen in the Jenkins- system Administration-Administration plug-ins, as shown in the following figure:

In order to facilitate the demonstration, I use my git version library on open source China as a demonstration.

4.2 configure MSBuild

To demonstrate Jenkins's support for .NET projects, I have created a .NET project on Open Source China at https://gitee.com/zhoufoxcn/GoodAppCodeMaker.git. If there is a .NET project in the continuous integration project, it is recommended to install Jenkins on Windows. The installation process is the same as on CentOS7.

Click the "Global tool configuration" link shown in the previous image to find the MSBuild node, as shown in the following figure:

I use VS2015, so the version of MSBuild is 14.0. If you don't want to install Visual Studio completely, you can install MSBuild Tool. Here I install Microsoft Build Tools 2015 at the download address: https://www.microsoft.com/en-us/download/details.aspx?id=48159

The installed path is C:\ ProgramFiles (x86)\ MSBuild\ 14.0 the path to MSBuild.exe is: C:\ ProgramFiles (x86)\ MSBuild\ 14.0\ Bin, which is the value in the "Path to MSBuild" column in the figure above.

4.3 configure Maven

To demonstrate Jenkins's support for the Java project, I use one of my open source projects in China at https://gitee.com/zhoufoxcn/CodeGenerator.git, which uses Maven for this Java project. So you need to download Maven, download the URL: http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz, extract the downloaded package file to a path, and then remember this path, which will be used immediately below.

Click the "Global tool configuration" link shown in the previous image to find the Maven node configuration information, as shown in the following figure:

The value of the column "MAVEN_HOME" in the image above is the path of the decompressed Maven. Friends who have done Java know that environment variables are often used in Java to store some work paths, such as JAVA_HOME, CLASSPATH, CATALINA_HOME and so on.

5. Verify configuration

In order to verify that our configuration works properly, we will verify it with the two projects just mentioned (in fact, I wanted to mention the .net core2.0 project, which can be run under Linux, but later I think it is similar to the Java project.

The git version library addresses of the two sample projects:

CodeGenerator: https://gitee.com/zhoufoxcn/CodeGenerator.git, using Maven's Java project.

GoodAppCodeMaker: https://gitee.com/zhoufoxcn/GoodAppCodeMaker.git, a C # project developed using VS2010.

Creating a continuous integration project is divided into six parts: General, source management, build trigger, build environment, build and post-build operation. Make full use of these parts, you can achieve a lot of powerful functions, but also save a lot of energy.

5.1 create a continuous integration project for the Java project

Click the "New" link on the home page, as shown in the following figure:

Select "build a free-style software project", then fill in the name of the project, click "OK" and the following interface appears:

General department generally does not have much to pay attention to, after filling in some information for identification and description, you can set up the source code management part.

Jenkins supports common source code control systems, such as CVS/SVN/Git. Because the example project uses git as the source code control tool, it needs to fill in the relevant information, such as git version library address, authentication information, source code branch information. When you use it for the first time, you need to create it because there is no version library authentication information. Click the "Add" button next to "Credentials", as shown below:

The following is a screenshot of the Git authentication credentials I created for Open Source China:

There are no special settings in the build trigger and the build environment in this project, as shown in the following figure (in some projects, you may be required to compile the project each time the code is submitted or compile the project at a regular time every day):

Then set the construction-related parameters, such as selecting the Maven we configured and the goals of the specified Maven, as shown below:

5.2 create a continuous integration project for the C# project

There is not much difference between creating a continuous integration project for C# and creating a continuous integration project for Java. For example, in the source code control part, the identity credential information is reused except for the git version library URL, as shown in the following figure:

In addition, because there are different ways to compile projects in different languages Java and C #, there are some differences in the build node. The choice here is MSBuild, while you need to develop a project file at compile time, either based on the solution or based on the project, I choose to compile the entire solution here, that is, "MSBuild Build File" to specify, while using "Command Line Arguments" to specify the parameters at compile time, this can be viewed under the command line to see which parameters MSBuild supports and what is the significance.

So far, two continuous integration projects have been created, and you can see the project you just created on the system start page. Click the icon on the far right to build the project immediately.

It is important to note that if the C # project uses NuGet or the Java project uses Maven, make sure that the server with Jenkins installed can download the dll or Jar referenced by the project, otherwise the build will fail.

Click the "Task History" link on the left side of the Jenkins system to view the previous construction, as shown in the following figure:

If you compile a stamp, you can click the icon on the right side of the build to view the console output (marked by a red arrow in the image above). The interface is shown in the following figure:

Look at the figure above because Maven is not configured so that it cannot be compiled.

In addition, in Linux / {User_Name} / .jenkins / this directory will store a lot of intermediate process information about Jenkins (C:\ Users\ {User_Name}\ .jenkins\, {User_Name} is the name logged into the system if you are in Windows), for example, it will be saved to / {User_Name} / .jenkins / workspace/ after moving out of Jenkins (C:\ Users\ {User_Name}\ .jenkins\ workspace\ in Windows) If it is a jar or exe file, copy it to / {User_Name} / .jenkins / userContent/ (corresponding to C:\ Users\ {User_Name}\ .jenkins\ userContent\ in Windows), so that the virtual machine can be accessed through http://192.168.60.168:8080/jenkins/userContent/ (inside the virtual machine: http://localhost:8080/jenkins/userContent/).

6. Summary

This article describes how to use Jenkins for continuous integration of projects, demonstrating two common project types, Java and C#, respectively. Because of the time constraint, it only briefly describes how to configure and create a basic continuous integration project. In fact, in addition to the functions demonstrated above, Jenkins can also notify the relevant personnel of the failure or success message after the completion of the build, and even automatically deploy to the server (usually deployed to the test environment for QA testing, or publish directly to the official server should be more careful).

Zhou Jinqiao

2017-10-15

Disclaimer: this article was first posted on my Wechat Subscription account: zhoujinqiaoIT, and then it will be posted on my CSDN, 51CTO and oschina blog at the same time. I will be responsible for answering questions here.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report