preface

What is continuous integration? Continuous Integration (CI). Continuous integration is a software development practice in which team development members integrate their work frequently, usually at least once per member, which means that multiple integrations may occur per day. Each integration is verified by an automated build (including compilation, release, and automated testing) to find integration errors as quickly as possible. Many teams find that this process greatly reduces integration problems, allowing teams to develop cohesive software more quickly.

What are some of the problems without continuous integration? The interface of the module project is not deployed in time, and the interface is unavailable. Every time you need to manually package the latest code for deployment, release the code, and deploy it online, it’s all manual. Easy to make mistakes. Waste of time.

Now what about the problem that continuous integration solves? Project build automation, integration of detailed information and history records, use of unified management, fixed deployment processes, integration at least once a day.

The installation

Here I use Tomcat with Jenkins to achieve the purpose of continuous integration.

First, install Tomcat

Download Tomcat from the official website. Tomcat.apache.org/.

Windows Service Installer (PGP, SHA512) is a 32-bit/64-bit version. And then you install them one by one.

Next, configure the environment variables:

CLASSPATH: (.; %JAVA_HOME%\lib\dt.jar; % JAVA_HOME %). Note the first sign dot!!

CATALINA_HOME: (D:\tool\apache-tomcat-7.0.57)

Path: (; %JAVA_HOME%; %JRE_HOME%\jre\bin) If you have configured the Java environment before, do not configure it again.

The installation is almost complete. Let’s type http://localhost:8080/ in the browser to see if the following page appears. If so, the installation is successful.

Install the JDK

To install the JDK, check out this article – www.runoob.com/java/java-e…

3. Install Jenkins

IO /download/ Now you can install Jenkins. Go to the address to download Jenkins’ war package. Then place the war package under the directory of the previously installed Tomcat (C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps — my address is this).

Then type http://localhost:8080/jenkins/ in your browser. If the installation is successful, Jenkins’ interface will appear

Here according to the prompt we find under the directory can get the password. Next comes the option to install the plugin, which is recommended for beginners.

Sometimes the installation fails or the link fails, just try it a few times. It’s usually a network problem.

With the administrator account created, Jenkins can be configured.

configuration

First, plug-in installation

There are three plug-ins that need to be installed: MSBuild Plugin, Publish Over SSH, and Email Extension Plugin. The former is for compiling, the latter is for connecting to the server, and the last is for configuring mail delivery.

2. Mailbox configuration

The system starts to configure the email sending function.

First go to Jenkins Location and set up the email address of the system administrator.

Then go to the Extended E-mail Notification Settings, where you can start setting up the configuration for sending messages. Here I use the CONFIGURATION of QQ mailbox.

SMTP Server – SMTP server configuration

Default User Email suffix – The suffix of the Default email

User Name – set the sender information ([email protected] type 12345678 here)

Password – this is not to fill in the Password, enter the SMTP authorization code

SMTP port — The default SMTP port is 465

Default Content Type — The format of the message Content

Default Recipients — The Default recipient

Default Subject — Default Subject

Default Content — Default Content

Template for configuring email notification content:

<! DOCTYPE html> <html> <head> <meta charset="UTF-8">    

<title>${ENV, var="JOB_NAME"}- the first${BUILD_NUMBER}The build log </title> </head> <body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4"    

    offset="0">    

    <table width="95%" cellpadding="0" cellspacing="0"  style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif"> <tr> This email is automatically sent by the system, no need to reply! <br/> Dear colleagues, the following is the list${PROJECT_NAME }Project build information </br> < TD ><font color="#CC0000"> < span style = "box-sizing: border-box! Important${BUILD_STATUS}</font></td>   

        </tr>    

        <tr>    

            <td><br />    

            <b><font color="#0B610B"</font></b> <hr size="2" width="100%" align="center"/></ tr> <tr> < TD >< ul> <li>${PROJECT_NAME}</li> <li${BUILD_NUMBER}</li> <li>${CAUSE}</li> <li> Build status:${BUILD_STATUS}</li> <li> Build log: <a href="${BUILD_URL}console">${BUILD_URL}Console </a></li> <li> build Url: <a href="${BUILD_URL}">${BUILD_URL}</a></li> <li"${PROJECT_URL}ws">${PROJECT_URL}Ws </a></li> <li> Project Url: <a href="${PROJECT_URL}">${PROJECT_URL}</a></li>    

                </ul>    

 

<h4><font color="#0B610B"</font></h4> <hr size="2" width="100%" />

$FAILED_TESTS<br/>

 

<h4><font color="#0B610B"> Recently submitted (#$SVN_REVISION)</font></h4>

<hr size="2" width="100%" />

<ul>

${CHANGES_SINCE_LAST_SUCCESS, reverse=true, format="%c", changesFormat="<li>%d [%a] %m</li>"}</ul> Detailed submission: <a href="${PROJECT_URL}changes">${PROJECT_URL}changes</a><br/>

 

            </td>    

        </tr>    

    </table>    

</body>    

</html>Copy the code

Publish over SSH

Let’s start configuring the SSH connection server configuration.

Just follow the above configuration.

Passphrase — password or key

Name – The Name of this connection service

Hostname – The address of the server

Username – the server Username

Remote Directory — The Remote Directory to transport

Use password authentication, or Use a different key – This option can be used to set another password

4. Global tool configuration

Enter the Global Tool Configuration to set the Global Tool Settings. First, you need to set git. If you do not set git, you may not be able to pull the code. Then set MSBuild, which is used to compile the project.

build

At this point, the installation and configuration are complete. We can start building the project in earnest. Here we divide into pairs. Net and.net Core projects for integration. Git is used to submit and pull the code.

Here we choose to start building a free-style project.

Then fill in the project description

This is where you start setting up source control. Select Git and enter the address. Then click Advanced, set username and password, and return to this page to select the certificate you just set

I then start building triggers, where I set the trigger time to poll every minute. You can decide the time according to the situation

The build environment here is up to you.

This is where you start building the configuration. Here I have chosen to build the VS project using MSBuild.

/t:Rebuild

/p:Configuration=Release

/p:DeployOnBuild=true; PublishProfile=FolderProfile /p:OutputPath=D:\Jenkins_PublishCopy the code

MSBuild Build File -- The directory to build (for example, in my case C:\Windows\ServiceProfiles\LocalService\.Jenkins \workspace\Test_Net\WebApplication1\WebApplication1). Csproj) Command Line Arguments -- build Command Rebuild -- Rebuild Configuration=Release -- generate Release version DeployOnBuild=true; PublishProfile=FolderProfile -- set to run the deployment build and execute the production directory under FolderProfile (FolderProfile file in Properties directory) OutputPath -- OutputPathCopy the code

Here I look at the SMS configuration to start configuring operations after the build is complete.

Now that we’re all configured, we can go back to the main page and start building.

Click Build Now and soon we get an email

Here we use Git and Jenkins to build. Net project continuous integration is complete. So let’s look at theta. How Net Core projects do continuous integration. Since.net Core projects can be deployed on Linux, we’ll use Linux as the server. Integrate locally and publish to Linux. All other operations are the same, except that the build operation differs from the post-build operation. We’ll focus on build operations and post-build operations.

dotnet restore

dotnet build   

dotnet publish  -c:Release -r centos.7-x64 --self-contained false-o C: \ Windows \ ServiceProfiles \ LocalService \. Jenkins \ workspace \ Test_Net_Core \ WebApplication2 \ bin \ Release \ netcoreapp2.2 \ cento s.7-x64echoCompression begancdC: \ Windows \ ServiceProfiles \ LocalService \. Jenkins \ workspace \ Test_Net_Core \ WebApplication2 \ bin \ Release \ netcoreapp2.2 7 a to z -tzip publish.zip C: \ Windows \ ServiceProfiles \ LocalService \. Jenkins \ workspace \ Test_Net_Core \ WebApplication2 \ bin \ Release \ netcoreapp2.2 \ cento s.7-x64echoEnd of the compressionCopy the code

Dotnet publish -- publish -c:Release -- Release -r centos.7-x64 -- Linux --self-containedfalse-o D:\Jenkins_CorePublish -- Publish files to this directoryCopy the code

A compression command is added to compress the release file into a compressed package, which is convenient for subsequent uploading to the server. SSH upload Uploads only files. No upload folder. So we need to compress. Upload it to the server and decompress it.

Then start to configure post-build operations. Configure the same email information as the above. Here we mainly configure how to connect to SSH.

The important thing to note here is the uploaded source file. The key directory is your Jenkins work directory, so it needs to be relative to the location

Here you configure uploading files and decompressing them and then restart the service on the Linux server to publish.

cd /home/hlz

rm -f publish

unzip publish.zip

rm -f publish.zip

cd /root

systemctl  enable Test.service

systemctl  start Test.service

systemctl  status Test.serviceCopy the code

conclusion

At this point Jenkins continuous integration is done on Windows. There are some details in the middle need to configure can be free to play, the main process is probably so much. This is done by continuing the integration locally and then transferring to the Linux server via the Publish over SSH plug-in. Net Core project deployment. We could also deploy Jenkins directly on Linux, eliminating the need to connect to the server. The problem can be solved directly on the server in one go.

Escape does not hide too, the face is not necessarily uncomfortable. Turn around is not necessarily the weakest.

Please scan the qr code below and join me on the road to design mode!