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.
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.
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
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
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
GitLab :
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
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