Gitlab combined with jenkins to implement code online

Prepare the environment:
If the performance of the notebook can be prepared, 3 virtual machines can be prepared! The roles are as follows:

  • jenkins node 192.168.232.135
  • gitlab node 192.168.232.136
  • lamp node 192.168.232.137

Start building after planning

1. Install docker (all 3 are installed)

Here is the offline installation of docker

1. Upload the offline installation package to the server

[root@localhost ~]# tar zxf docker-19.03.9.tgz
[root@localhost ~]# cp docker/* /usr/bin/
[root@localhost ~]# chmod +x docker.service
[root@localhost ~]# cp docker.service /etc/systemd/system
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start docker

2.docker image acceleration configuration
cd /etc/docker
Upload the modified daemon.json to this directory
restart docker

[root@localhost ~]# cd /etc/docker/
[root@localhost docker]# ls
daemon.json  key.json
[root@localhost docker]# cat daemon.json 
{
  "registry-mirrors": ["https://q3u0qv3z.mirror.aliyuncs.com"],
   "insecure-registries":["192.168.232.136"]
}
[root@localhost docker]# systemctl daemon-reload
[root@localhost docker]# systemctl restart docker

Second, install jenkins
Node: 192.168.232.135
1. Upload the jenkins installation package

[root@localhost ~]# tar zxf jenkins-zh.tar.gz 
[root@localhost ~]# docker load -i jenkins-zh.tar
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
jenkins             latest              5ce09eb3e8c3        4 months ago        755MB
[root@localhost ~]# docker run --name jenkins -d -p 8080:8080 jenkins
abc3c76bbb68a9d150638cf32cfb9e3f4442369f52d75c87e191a011a96c0f8b

Browser access: http://192.168.232.135:8080

2. Modify to Chinese font


3. Upload the jenkins acceleration package: do jenkins acceleration

[root@localhost ~]# docker cp default.json jenkins:/var/jenkins_home/update

Restart jenkins: dokcer restart Jenkins

[root@localhost ~]# docker restart jenkins
jenkins

4. Install git and ssh


After installing git, choose to return to the home page to continue installing ssh

3. Configure gitlab

Upload the gitlab installation package

[root@localhost ~]# tar zxf gitlab.tar.gz 
[root@localhost ~]# docker load -i gitlab.tar
[root@localhost ~]# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
twang2218/gitlab-ce-zh   latest              18da462b5ff5        2 years ago         1.61GB
[root@localhost ~]# docker run --name gitlab -d -p 80:80 twang2218/gitlab-ce-zh
0e1f90bd429289fad0cbc62c8bc87dc7580fc3de176441400ec3eeb3ed610545

Wait about 5 minutes to access gitlab

For the first access, you need to set the default administrator account: root's login password, 8 digits

After setting, log in with root user and new password.

We create a project on gitlab to store our code


We clone the project repository to the local! Test if it can be cloned! Create an empty directory on windows! Used to store the project warehouse!
Open git bash to start cloning the project

Copy and paste these commands in the gitlab repository and execute them to configure users and clone the repository


The first clone will prompt to enter the login account and password of gitlab, enter the root account and password set by gitlab before.

After success, a directory with the same name as my project will be generated in the current directory

Let's upload a code file to gitlab and test it!
Create a new 1.txt in the project directory

do a local commit



1.txt file can be seen in wordpress project

Fourth, start integrating jenkins

Create a task in jenkins:



start build task

Click on this build task and see the console output

We can see that the final build succeeded!
So far, jenkins and gitlab have been successfully combined!

Posted by sajidfiaz on Thu, 05 May 2022 01:38:43 +0300