Linux-Jenkins+gitlab tool

JenKins

jenkins official document: https://www.jenkins.io

Jenkins:

Jenkins is the leader of open source CI&CD software, providing more than 1,000 plug-ins to support construction, deployment, and automation to meet the needs of any project.

CI&CD:

  • Continuous integration focuses on gathering the work of various developers into a code warehouse, usually several times a day, the main purpose is to find integration errors as soon as possible, so that the team can be more closely integrated and better collaborate.
  • The purpose of continuous delivery is to minimize the friction inherent in the team during the deployment or release process. Its implementation can usually automate each step of the build and deployment so that the code can be released safely at any time (ideally).
  • Continuous deployment is a higher degree of automation. Whenever there are major changes to the code, it will be built/deployed automatically.

surroundings

CPU name ip
gitlab 192.168.1.20
jenkins 192.168.1.19

Install jenkins

1. Download jenkins

wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat/jenkins-2.222-1.1.noarch.rpm
--2020-07-21 15:14:48--  https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat/jenkins-2.222-1.1.noarch.rpm
正在解析主机 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
正在连接 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:66093056 (63M) [application/x-redhat-package-manager]
正在保存至: “jenkins-2.222-1.1.noarch.rpm”

100%[======================================>] 66,093,056  1018KB/s 用时 59s    

2020-07-21 15:15:48 (1.06 MB/s) - 已保存 “jenkins-2.222-1.1.noarch.rpm” [66093056/66093056])

[root@jenkins ~]# yum -y install jenkins-2.222-1.1.noarch.rpm

2. Modify the configuration file

PS: The port of jenkins is 8080 by default. If it is on the same host as gitlab, you need to modify the port

[root@jenkins ~]# vim /etc/sysconfig/jenkins 
修改:
	JENKINS_USER="root"
	JENKINS_PORT="8081"  //此处环境不在同一主机上 ,则不需要修改
[root@jenkins ~]# systemctl start  jenkins
[root@jenkins ~]# systemctl enable  jenkins
jenkins.service is not a native service, redirecting to /sbin/chkconfig.Executing /sbin/chkconfig jenkins on

3. Log in to jenkins

It may take a long time here, please be patient! ! When Jenkins is ready, the browser will automatically reload.

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-rY74Liv1-1595329796453)(C:\Users\Administrator\Desktop\Photo\Jenkins\1.png)]

4. Enter the password to enter the jenkinsweb page

[root@jenkins ~]# cat /var/lib/jenkins/secrets/initialAdminPassword 
467c8503f0ee4e4ea592cd043e1a0847

PS: Copy the information viewed above to the administrator password box below, and then click Continue.

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-DNr5UsYR-1595329796457)(C:\Users\Administrator\Desktop\Photo\Jenkins\2.png)]

5. Choose to install the plugin

Here select the "X" in the upper right corner to enter the jenkinsWEB page!

6. Change jenkins web login password

Upper right corner >> admin click the drop-down triangle >> Configure >> Password field >> modify password >> save

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-MRn0ZDTe-1595329796458)(C:\Users\Administrator\Desktop\Photo\Jenkins\3.png)]

Case (Jenkins associated gitlab)

  • The server is closed firewall and SELinux.

Download plugins

[root@jenkins ~]# tar zxf jenkins-plugins.tar.gz 
[root@jenkins ~]# cd plugins/
[root@jenkins plugins]# cp * /var/lib/jenkins/plugins/
cp: 略过目录"ace-editor"
cp: 略过目录"ant"
cp: 略过目录"antisamy-markup-formatter"
cp: 略过目录"apache-httpcomponents-client-4-api"
cp: 略过目录"authentication-tokens"
......
[root@jenkins plugins]# systemctl restart jenkins.service 

1. Create a project

Click the logo in the upper left corner >> back to the main page >> select the new project "New Item" >> fill in the project name >> select the project type "Freestyle project" >> save

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-4w2nMA98-1595329796461)(C:\Users\Administrator\Desktop\Photo\Jenkins\4.png)]

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-Exw2GM1I-1595329796462)(C:\Users\Administrator\Desktop\Photo\Jenkins\5.png)]

2. Configure git

Configure the project >> Source Code Management >>git >> Fill in the repository URL ([email protected]:dev/benet.git)> >> If the authentication is successful >> save

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-UedTq182-1595329796464)(C:\Users\Administrator\Desktop\Photo\Jenkins\6.png)]

GitLab :

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-8uaBmVcm-1595329796465)(C:\Users\Administrator\Desktop\Photo\Jenkins\7 .png)]

3. Open the project

Select the project >> select "build now" on the left >> a blue mark appears in the build history below >> select the blue mark drop-down list >> console output >> output execution process

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-R4NuBLfS-1595329796467)(C:\Users\Administrator\Desktop\Photo\Jenkins\8.png)]

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-EnImj3He-1595329796467)(C:\Users\Administrator\Desktop\Photo\Jenkins\9.png)]

4. Verification

PS: Check the /var/lib/jenkins/workspace directory on the jenkins server, there will be a folder with the same name as the project, save all the code of git clone

[root@jenkins ~]# cd /var/lib/jenkins/workspace/
[root@jenkins workspace]# ls
项目1
[root@jenkins workspace]# cd 项目1/
[root@jenkins 项目1]# ls
new1.txt  new2.txt  new.txt

Guess you like

Origin blog.csdn.net/weixin_45191791/article/details/107496418