Detailed explanation of CICD (10) - Jenkins+Gitlab actual combat

Today, I will continue to introduce the relevant knowledge of Linux operation and maintenance. The main content of this article is the actual combat of Jenkins+Gitlab.
In the above CICD detailed explanation (8) - gitlab installation and configuration , we have completed the configuration of Gitlab. Today, we will use Jenkins to cooperate with Gitlab for project combat.
In this actual combat, the devices and their IP addresses are as follows:
Jenkins: 192.168.136.20
Gitlab: 192.168.136.11

1. Git plugin installation in Jenkins

First, we first install the Git plugin in Jenkins, we search for Git in the plugin, and choose to install Git and Gitlab, as shown below:
insert image description here
insert image description here
Note that there may be problems with the installation of these two software, when I install this step There have been a lot of errors, and the plugin installation failed. I have compiled the solution to this problem separately. For students who have the same problem, please refer to: CICD Detailed Explanation (14) - After the Jenkins plugin installation fails to resolve
, because Jenkins is used to manage Gitlab, Therefore, there must be a Git client on the Jenkins device. Otherwise, although there is a Gitlab plug-in on Jenkins, there is no Git command locally, and project management cannot be performed.
On the Jenkins device, after configuring the REPO source of Tsinghua University (for the configuration, please refer to the article CICD detailed explanation (8) - gitlab installation and configuration ), execute the command:

yum install -y git

This completes the installation of the Git client on the Jenkins device.

2. Jenkins key authentication

After completing the above configuration, we also need to configure the Jenkins device to perform key authentication on the Gitlab device, otherwise, we will also fail to configure due to Gitlab's authentication.
On the Jenkins appliance, execute the command:

ssh-keygen

To generate the public and private key pair of the device, execute the command:

cat /root/.ssh/id_rsa.pub

You can view the public key of this device, and the execution result is as follows:
insert image description here
After completing the above configuration, we copy the public key of the Jenkins device to the user authentication module of Gitlab, as shown below:
insert image description here
Note that after the above configuration is completed, we had better Configure, start Gitlab, and execute the command:

gitlab-ctl reconfigure
gitlab-ctl start

3. Jenkins project pull

Finally, we need to configure Jenkins to pull Git projects, select a project, and view its SSH and HTTP addresses, as follows:
insert image description here
Back on the Jenkins machine, we create a new project. Since we have installed the Git plugin, we can choose the Git type when we build, as shown below:
insert image description here
We add the Git address of the Git project we just copied in the URL section. However, we should pay attention here because our Git project is still There is no configuration, so this address cannot be accessed, we need to manually modify gitlab.example.com to Gitlab's IP address.
After that, we also need to add an authentication, here, we choose the authentication method is SSH username and private key, as shown below:
insert image description here
The private key of the Jenkins device can be executed by executing the command:

cat /root/.ssh/id_rsa

To check, the results are as follows:
insert image description here
After copying all the private keys, the configuration is as follows: After
insert image description here
configuring the authentication method, if you find that there is no red error message in the Git project, it means that our project configuration is successful, and the result is as follows:
insert image description here
https:// blog.csdn.net/weixin_40228200

Guess you like

Origin blog.csdn.net/weixin_40228200/article/details/123883307