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

Deploy Jenkins+Gitlab for continuous integration

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Introduction to preface Jenkins

Jenkins is just a platform, and what really works is plug-ins. This is why jenkins is popular, because Hudson has all kinds of plug-ins in jenkins. Hudson is a continuous integration tool based on Java, which is used to monitor the repetitive work of programs. Hudson was later acquired and became a commercial version. Later, the founder wrote a jenkins,jenkins that is far more functional than hudson.

Reference: Jenkins Chinese website

Before we get to the topic of deployment and installation, there are a few questions to figure out!

1. What is integration?

Refers to the process by which the code is compiled, released, and tested until it is online.

2. What is continuous integration?

Efficient and continuous integration of iterative code.

3. How to realize continuous integration efficiently and accurately

It is necessary to have an automated and visual platform to help us.

According to the above points, Jenkins is a platform that can achieve continuous integration.

4. Why is Jenkins to help us achieve continuous integration? 1) Jenkins is an open source continuous integration system based on JAVA code development.

Because it contains very rich plug-in support, we can easily get through all aspects of the version library, test build environment, and online environment. And rich and friendly notification users and developers, managers.

2) simple installation and maintenance

Installing Jenkins is not too complicated. And supports a common platform.

3) Java applications are commonly used

In the process of enterprise software construction, the application engineering of JAVA is slightly complex, due to complex construction and code online, and the restart of services. The whole process takes a lot of time, but Jenkins can well integrate the compilation mode of maven, and uses the support of automated plug-ins and custom development scripts. Therefore, it is widely used in the continuous integration platform of JAVA project.

Most of the software packages used next are downloaded from Tsinghua Open Source Mirror Station.

Deploy and install gitlab1 and install gitlabs [root @ jenkins ~] # wget https://mirrors-i.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.9.8-ce.0.el7.x86_64.rpm[root@jenkins ~] # rpm-ivh gitlab-ce-11.9.8-ce.0.el7.x86_64.rpm # because I'm not going to do domain name resolution So you need to modify its configuration file root@jenkins ~] # vim / etc/gitlab/gitlab.rb external_url 'http://192.168.20.2' # change the original domain name to native IP [root@jenkins ~] # gitlab-ctl reconfigure # reconfigure gitlab, even if you don't modify the configuration file, you need to reconfigure gitlab [root@jenkins ~] # netstat-anpt after installation | grep-w 80 # make sure that port 80 is listening 2 and configure gitlab

When the client accesses the IP address of the server, you can see the following interface (configure password and log in):

Upload the server public key (the next operation is much the same as on github), and first generate the key pair on the server:

[root@jenkins ~] # ssh-keygen-t rsa-C "916551516@qq.com" [root@jenkins ~] # cat ~ / .ssh/id_rsa.pub # View the generated public key and copy its contents ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeOeInVnfQiVdTTiA8MyaIuMdrtQUce1BpiBR8d2IAWS4PVznRub+m9hRR2vRRK3K3T4oMGpgjvj7s5n8n4AcFojDRsNgCrpprz4jlTykm0okQclXtOzeFfpLzwp08l0mmb3ZotuU/iK5sYUh70MAxG/gSzfZ5Cscmba+HGSYksN75BRkYBOT3VBJHuqhdHEIrmK0uOUU4/F3ImqrBoOs3/2c6aI5AxrHGy3aVdWAcg2Pg541djMD74DJCaVpPj08GQNZZBmN/p7Ft3v6Vi+jqty7CQF+uhs1x3oD/tka88F/4A/rMR862TqATQ+Uuqn2LOfrvGR6kzJH5MtyKOumB 916551516@qq.com

Then go back to the web interface:

After adding, it is as follows:

Create a library:

Go back to the server and clone the library you just created:

[root@jenkins ~] # git clone git@192.168.20.2:root/test01.git # Clone [root@jenkins ~] # cd test01/ # enter the cloned library [root@jenkins test01] # ls # the contents in this directory are the same as those just after the web page has created the library. README.md# self-report [root@jenkins test01] # git config-- global user.name test [root@jenkins test01] # git config-- global user.email "test@test.com" # upload files to the remote library for testing [root@jenkins test01] # echo "aaaaaaaaaaaa" > test.txt [root@jenkins test01] # git add test.txt [root@jenkins test01] # git commit-m "commit from local" [root@jenkins test01] # git push origin master # push to the remote library

Refresh the library page of the web interface to see the test file you just pushed:

At this point, it shows that the gitlab configuration is correct, and it can come to an end.

Second, deploy and install Jenkins1, Install Jenkins# download and install [root@jenkins ~] # wget https://mirrors-i.tuna.tsinghua.edu.cn/jenkins/redhat/jenkins-2.172-1.1.noarch.rpm[root@jenkins ~] # rpm-ivh jenkins-2.172-1.1.noarch.rpm [root@jenkins ~] # rpm-ql jenkins # to view the storage path of the corresponding files [root@jenkins ~] # sed-I's Universe Port = "8080" / JENKINS_PORT= "8081" / g'/ etc/sysconfig/jenkins # modify its listening port [root@jenkins ~] # / etc/init.d/jenkins start # launch Jenkins [root @ jenkins ~] # netstat-anpt | grep 8081 # make sure the port is listening on Jenkins 0: 8081: * LISTEN 65172/java 2, Configure the web interface for Jenkins

The client accesses the listening port 8081 of the Jenkins server and then copies its administrator password when prompted. As follows:

[root@jenkins ~] # cat / var/lib/jenkins/secrets/initialAdminPassworde501f94f2d914b22ae6ef7384b34531a

Next, you can install some basic plug-ins, and click on its recommended installation, as follows (I can skip this step by uploading my package directly to the specified directory, download my package and do the same as I do):

I don't have the recommended plug-ins to install it, I choose to install it in the following ways:

[root@jenkins ~] # tar zxf jenkins-plugins.tar.gz-C / var/lib/jenkins/ [root@jenkins ~] # / etc/init.d/jenkins restart # restart Jenkins

Note: if you install it in my way, you need to disconnect the external network when you access it again.

After the above configuration, you can see the working page of Jenkins, as follows:

3. Configure the warehouse code for Jenkins to pull Gitlab

[root@jenkins ~] # cat ~ / .ssh/id_rsa # copy everything you see, including the "- -" line-BEGIN RSA PRIVATE KEY-MIIEowIBAAKCAQEAnjniJ1Z30IlXU04gPDMmiLjHa7UFHHtQaYgUfHdiAFkuD1c50bm/pvYUUdr0UStyt0+KDBqYI74+7OZ/J+AHBaIw0bDYAq6aa8+I5U8pJtKJEHJV7Ts3hX6S88KdPJdJpm92aLblP4iubGFIe9DAMRv4Es32eQrHJm2vhxkmJLDe+QUZGATk91QSR7qoXRxCK5itLjlFOPxdyJqqwaDrN/9nOmiOQMaxxst2lXVgHINj4OeNXYzA++AyQmlaT49PBkDWWQZjf6exbd7+lYvo6rcuwkBfrobNcd6A/7ZGvPBf+AP6zEfOtk6g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AoGBAJGu+GSpxO/vRDfxaJGgclhEXpCahuL6ggUZcZSsUu/qiCq4cbSC26/9X7+cws3d5ow1vIZttM19meK1Z6r0qOii7GOX3vEWVsDyrt5rpVNSb/M6F1D7MV07YV1esSxZGB9Spa7TAzuE2bwkMIDAu72nCRx+MO83vHSFRpkln+7O-END RSA PRIVATE KEY- at the beginning and the end

You can see the following page to show that the configuration is correct:

The terminal views the files synchronized locally:

[root@jenkins ~] # ls / var/lib/jenkins/workspace/web01README.md test.txt [root@jenkins ~] # cat / var/lib/jenkins/workspace/web01/test.txt aaaaaaaaaaaa III. Configure Jenkins+Gitlab to achieve continuous integration

Next comes the key part of this document.

For convenience, you can download the plug-in I provided before proceeding to the following configuration.

Then you will see some red tips, never mind, the drop-down page is as follows:

Upload the packages I provided in the following order: gitlab-oauth==== "gitlab-plugin =" windows-slaves = "ruby-runtime =" gitlab-hook

Upload the above packages in turn according to the following actions:

After the plug-in is uploaded, it can be done.

I would like to add here that if you want to install the plug-in online, you can change the plug-in source to the URL of the Jenkins Mirror Station of Tsinghua University. Here you attach a link to change the method. Please add a link description and refer to yourself to make changes.

The modification process is as follows:

The additional content ends here.

Since most of the next operations are dots, there will be no screenshots, only the more critical ones.

Click: system Management = "Global Security configuration =" Authorization Policy, and then do the following:

Click: system Management = system Settings, and then do the following:

Then do the following:

Generate a token at the terminal and copy:

[root@jenkins ~] # openssl rand-hex 10 # copy the following string dbd47a73dba048febf4f

Go back to the web page of Gitlab and do the following:

Next, we need to go to Jenkins to find the URL we need.

The following actions are performed on the web page of Jenkins:

After seeing the above, we need to splice the URL of Jenkins, which is probably the access address of Jenkins + / job....= authentication tokencode. The spliced ones I have here are as follows: http://192.168.20.2:8081/job/web01/build?token=dbd47a73dba048febf4f

Then go back to the gitlab page and enter the URL of Jenkins:

After adding, on the drop-down page, click the following to test:

At this point, the continuous deployment is complete, and the next step is testing. Submit the code to gitlab on the terminal to check whether Jenkins has automatic synchronization, as shown below:

# submit a new code to gitlab [root@jenkins ~] # cd test01/ [root@jenkins test01] # echo "dffffffffdfdfdfdf" > chixu.txt [root@jenkins test01] # git add chixu.txt [root@jenkins test01] # git commit-m "chixu bu shu test" [root@jenkins test01] # git push origin master

Jenkins can see the following to show that the continuous deployment configuration is complete. As follows:

Forget it, let's take a look locally:

[root@jenkins test01] # cat / var/lib/jenkins/workspace/web01/chixu.txt # is the file dffffffffdfdfdfdf that we just submitted

-this is the end of this article. Thank you for reading-

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: 229

*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

Servers

Wechat

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

12
Report