[. NetCore] Based on jenkins and gitlab's continuous compilation and release, jenkinsgitlab

Source: Internet
Author: User

[. NetCore] Based on jenkins and gitlab's continuous compilation and release, jenkinsgitlab

Cutting-edge

In fact, I originally wanted to call the title continuous integration, but later I looked at the content and only published this action, and the content such as automated testing was not involved, so it should be more appropriate to change the name to continuous compilation and publishing?

Problem background

In fact, the traditional release method is usually packaged locally by the developer and then passed to the test. After the test is completed, the package is sent to the Project Manager or implementer for deployment, non-Internet projects may be well completed through human operations. Although it may be bumpy, this method is inefficient for Internet products, it may take a lot of time to package verification for each iterative development and test deployment. In this case, the automation solution is particularly important.

According to object-oriented understanding, compiling, publishing, and other operations are encapsulated and abstracted to reduce repetitive processes (is everything an object)

What is jenkins?

Since the title is based on jenkins, what is jenkins? I copied one from Baidu's explanation: Jenkins is an open-source software project and a continuous integration tool developed based on Java. It is used to monitor continuous repetitive work, it is designed to provide an open and easy-to-use software platform to enable continuous software integration.

Since it is a tool for continuous integration, there must be some release functions. SO we will use jenkins to implement our demands, when can our company see a real continuous integration approach?

Installation skills:

Rpm installation method:

rpm -ivh XXXX.rpm

Install and configure jenkins

Installation:

1, to install jenkins, you must first install JDK, first from the official find a jdk address (rpm installation): jdk-8u161-linux-x64.rpm, find the jdk-8u161-linux-x64.rpm, rpm installation.

2, jenkins rpm download, give a address: jenkins-2.89.4-1.1.noarch.rpm, then rpm install

3. Disable the firewall after installation (or open port 8080)

4. service jenkins start; Enable jenkins

Configuration:

Open ip: 8080 in the browser

 

Find the key information input based on the red letter directory

Select the first recommended installation. Wait for a while, and the installation is complete. The Initialization Configuration in the first step ends here.

 

. NETCore Installation

Refer to the official installation method of Microsoft

Git Installation

  Since we want to be based on gitlab and jenkins, you have to install a git to pull source code to the local ah, the installation method is as follows: commit statement execution (refer to the https://www.cnblogs.com/gsliuruigang/p/7899803.html)

Yum-y groupinstall "Development Tools" // download the compilation tool yum-y install zlib-devel perl-ExtUtils-MakeMaker asciidoc xmlto openssl-devel // download the dependency package wget dependency-zxf v2.16.2.tar.gz // decompress the file cd git-2.16.2/
Autoconf
. /Configure -- prefix =/usr/local/gitmake & make install // compile and install export PATH = "/usr/local/git/bin: $ PATH "// configure the Global PATH source/etc/profile // make the configuration take effect

Gitlab Configuration

Logon ip: 8080. Go to the management plug-in and install the GitLab plug-in, as shown in

  

Open gitlab address --> personal settings --> account --> copy Private token backup

  

Jenkins --> System Management --> system settings --> Find gitlab

Click add.

  

Click test connection. If success is displayed, the connection is successful.

 

 

Task Construction

Go back to the jenkins homepage --> create a task --> enter a name --> Generate

1. General

As shown in, gitlabconnection selects the previously configured information

  

 

2. Source Code Management

Source code management mainly configures the information of the source code library. The specific configuration is shown in the following two figures. If no error is reported for the above operations, it indicates that the operation is successful. If an error is reported, a red message is prompted under the Repository URL, the branch Specifier of jenkins builds the input branch, so select a branch that exists in the current library. Credentials can be performed through ssh or http. If you use ssh, You need to perform authentication by using the public/private key. We use the Username and password method here, so select the Username with password option.

  

 

3. Create a trigger

We select Poll SCM as the building trigger, as shown in. This indicates building every 5 minutes. You can also select the webhook method to build the trigger by submitting, I will study this in the future (at present, our company does not have this requirement)

4. Build

These linux commands should be relatively simple and everyone should be able to understand that they are actually simulating manual operations to execute dotnet restore and dotnet publish actions in a directory, finally, I set the publish directory to the bin/release directory.

5. Execute build

Click build now. If no error is reported, the compiled code will be available in/var/lib/jenkins/workspace/test/bin/release.

Continuous Release

The above is just to get the code from gitlab and execute the compilation. After the compilation, how should we release the code to the specified server? We can't simply use the jenkins server, so what we need to do next is to release the compiled program to the desired server. Fortunately, jenkins also considered this requirement. There is a publish over ssh plug-in that can help us do this well.

Go back to the previous plug-in download and download publish over ssh.

Go back to the previous gitlab configuration, and now there are more Publish over SSH configurations, as shown in, here we also chose to use the user name and password for operations (you can also use ssh for authorized login)

After the configuration is completed, we re-enter the task and find an additional Build Environment, as shown in the following figure. The red letter can be ignored (it should be a jenkins bug)

Source files indicates the information of the file to be copied (ps: The Directory here is relative to the workspace)

Remove prefix means to remove the prefix. Otherwise, the corresponding folder will be created. Here I only need the file, so the entire

If the remote directory folder does not exist, it will be created on the server.

The command to be executed after the Exec command is copied successfully. Generally, a script is written on the server and directly executed on the server. after the dll command is run, the process will not end. Therefore, I actually wrote an empty file for this file. If it is actually used, the Supervisor can be used to enable process daemon, after each release, the corresponding process is killed and then started by the process daemon.

 

Click build. If there is no problem, you should see the publish content in the directory of the corresponding server. If the build fails, the console output here also has a very detailed log record. It should be easier to identify problems through logging.

Summary

Jenkins is a very powerful tool. Currently, it is only because of the company's need to start research, and many features have not yet come into use, including automated testing. In the future, we should focus on docker and k8s, and combine them with automated testing solutions to achieve real continuous integration.

Thinking about the docker solution also gives you an idea. In fact, you can replace the build script with the docker build method, then pull it to the image library, and finally notify the target server to pull the image again to generate it, the problem is how to generate the sequence number of the historical version library step by step?

Legacy questions: how can we achieve continuous integration or release of databases?

 

Author: Mango

Source: http://www.cnblogs.com/OMango/

About Yourself: Focus on. Net desktop development and Web Background Development, and begin to engage with Internet-related services such as microservices and docker (recently hacked by Internet architecture --)

The copyright of this article is shared by the author and the blog. You are welcome to repost this article. However, you must keep this statement without the author's consent and provide the original article link clearly on the article page. If you have any questions, please feel free to contact me in your insite.

  

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.