Continuous Integration: CI means that any changes made by anyone to the code base in a project will trigger the CI server to automatically build the project, automatically run tests, and even automatically deploy to the test environment. The nice thing about this is that you can always find problems and fix them. Because the cost of fixing a problem increases over time, the earlier you catch it, the lower the cost of fixing it. When you want to update your project, just submit the code to your code repository and leave the rest of the update deployment operation to the CI server, this time using JenKins CI tool.
-
Building Jenkins CONTINUOUS integration server can be divided into two steps, one is to install the required software on the server, the other is to configure our continuous integration project
-
Install all required software
-
Install and start Jenkins
- Download the latest RPM package from Jenkins’ official website
RPM -ivh xxx. RPM Install Jenkins // Start Jenkins /etc/init.d/ Jenkins start Enter http://xxx server ADDRESS :8080/ // The default port number is 8080Copy the code
-
The default JenKins port number is 8080, which conflicts with the default Tomcat port number, so we can change the JenKins port number to our own defined port number 9090
-
Change the file port number to /etc/sysconfig/jenkins and field JENKINS_PORT
Bash: /usr/bin/java: /usr/bin/java: D/Jenkins add /opt/jdk1.8.0_181/bin/ Java Generally, openJDK is installed by default using centos services. If you uninstall openJDK and install SUN JDK again, you need to add the path to this file. Vim /etc/sysconfig/jenkins // add the Java address vim /etc/init.d/ JenkinsCopy the code
-
-
Modify the port cannot be started. It may be that the firewall of the server does not add the listening of the port, which causes the access failure
Vim /etc/sysconfig/iptables Netstat -ntlp // Restart the firewall configuration (the configuration does not take effect without restarting the port.) service iptables restartCopy the code
-
Close the Jenkins
- Just add exit after the url of the Jenkins server. For example, if MY Jenkins address is http://localhost:8080/, I can just type http://xxx:9090/exit into the browser address bar to close the Jenkins service.
-
Restart Jenkies
// XXX :8080 is the Jenkins server address http://xxx:8080/restartCopy the code
-
Reload the configuration information
http://localhost:8080/reload Copy the code
-
Install the JDK
View java-related package information: The RPM - qa | grep Java (or RPM - qa | grep JDK, RPM after installation, Yum -y remove Java: yum -y remove Java: yum -y remove Java: yum -y remove Java: yum -y remove Java: yum -y remove Java: yum -y remove Java: yum -y remove Java: yum -y remove Java: yum -y remove Java: yum -y remove Java: yum -y remove Java: yum -y remove Java HTTP: / / https://blog.csdn.net/xyj0808xyj/article/details/52444694 / / to the specified directory tar - ZXVF JDK - 8 u181 - Linux - x64. Tar. Gz - C/opt / // Edit the profile vim /etc/profileexportJAVA_HOME = / opt/jdk1.8.0 _181export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH// Update the configuration filesource /etc/profile Copy the code
-
Install Tomcat
-
Download Tomcat8.5 from Tomcat8.5
-
Unzip the package directly to the JenKins server.
-
Forcibly shut down the tomcat command
/ / shutdowns of ps - ef | grep tomcat / / kill cannot close processkill -9 XXXX Copy the code
-
-
Install Git (on the JenKins deployment server)
Yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc yum install GCC Perl -extutils -makemaker If you have installed git but the version is too old, you can uninstall yum remove git, download git package, and decompress tar -vxf git-2.15.1.tar.gz -c /opt to go to git directorycd/opt/git-2.18.0/ Run the make prefix=/usr/ commandlocal/git all make prefix=/usr/local/git install echo "export PATH=$PATH:/usr/local/git/bin">> /etc/profile./ Configure environment variablessource/etc/profile. / Check the Git version with the new configuration file git --versionCopy the code
-
Install Maven (installed on JenKins deployment server)
- The background project is set up for Spring-Boot. Maven needs to be installed
- Download maven 3.5.4
Run the tar -zxvf apache-3.3.9-bin.tar. gz -c /opt command to add M2_HOME=/opt/tyrone/maven to the end of the /etc/profile file (Note that this is the maven installation path.)export PATH=${M2_HOME}/bin:${PATH}Reload the /etc/profile filesource /etc/profile Copy the code
-
GitLab server configuration
- Since the company has set up the Gitlab server, I have not configured Gitlab, but there are a lot of information on the Gitlab configuration website, which can be searched by myself.
-
-
Jenkins configures the new project configuration
-
Jenkins configuration
-
When entering Jnekins for the first time, follow the prompts to find the password to install the server
-
If the server can be connected to the Internet, the choice he recommended plug-in installed directly, if the server can’t connect the network, only in the corporate network environment, then you can offline download plug-in Jenkin and uploaded to our server, offline plug-in download address, this approach requires patience, because of the need to install the plug-in can be more than one or two, if your server can’t get to the Internet, I have a downloaded plug-in here, you can download it by yourself (download address)
-
To configure our Gitlab in the system configuration of Jenkins system management module, we need to log in to Gitlab to obtain APIToken
-
Generate SSH keys (on the Jenkins deployed server)
-
Configure SSH keys for subsequent projects that can be deployed to the application server through Jenkins
Ssh-keygen -t rsa Now your private key is stored in ~/. SSH /id_rsa, and your public key is stored in ~/. SSH /id_rsa.pub. As shown in the figure below, the public key is configured to the directory of each application server: /root/.ssh/authorized_keys. If there is no authorized_keys, the file will be created. Finally, test whether the application server can connect successfully, as shown in the following figureCopy the code
-
Next, Jenkins’ JDK, Git, and Maven are configured with global tools in the system management module. We have installed all of these tools previously and now configure them into Jenkins as shown below
-
-
-
New Project Configuration
-
Create a New Maven project (download the plugin if there is no Maven project option)
-
Start by configuring source management, as shown in the figure
-
Configure the project build trigger
-
Configure maven project compilation
-
Deploy the configuration of the application server after the project builds successfully
-
Tomcat restart script (stored in the same directory as Tomcat)
#! /bin/sh echo '#################### Start automatic deployment ####################' export JAVA_HOME=/usr/local/ jdk1.8.0 _181 path = `pwd` # current path tomcatPath=/data/XXXX/tomcat_gxxmt_8080 # specify tomcat file directory name cd ../$tomcatPath/bin Go to the bin directory of tomcat PID=$(ps -fu `whoami`|grep tomcat|grep -v grep|awk '{print $2}') if [ -z "$PID" ];then echo "no tomcat process" else ./shutdown.sh Stop the Tomcat service fi cd ../webapps Enter the Tomcat webapps directory rm -rf XXXX-api Delete previously deployed projects echo '#################### delete completed ####################' cd ../bin ./startup.sh # Start the Tomcat service echo '#################### Deployment completed ####################' Copy the code
-
The project was successfully constructed and released to the corresponding server to execute the corresponding script. Here we can see JenKins’ flexibility in configuring multiple Tomcat for multiple published application servers and deploying the application server configuration flexibly and automatically
-
Project build, compile and deploy successfully
-
-
-
-
Problems encountered with integration deployment
-
ERROR: Exception when publishing, Exception message [Exec timed out or was interrupted after 120,000 ms]
-
Solution: Script execution join ignores input (nohup….)
Nohup sh /data/gxxmt-api/restart.sh // When we run nohup, the log will be printed to the nohup. // If we do nothing, nohup.out will get bigger and bigger with each reboot. So I added cp /dev/null nohup.out to the script I executedCopy the code
In the Jenkins project, configure SSH Publishers to check Exec in pty
-
The default Jenkins home directory is generally installed on the system disk, and the historical version of the project deployment after running for a period of time, log files and work controls will occupy a lot of system space, which will cause the insufficient space of the system disk. First, we can modify the Jenkins home directory
// Change home directory vim /etc/sysconfig/jenkins JENKINS_HOME="/data/jenkins"Chown -r Jenkins: Jenkins /data/ Jenkins restart /etc/sysconfig/jenkins restartCopy the code
Second, we can set the discarding of historical builds in the project configuration
-
The Url is blocked: Requests to the local network are not allowed Gitlab Set Jenkins’ Webhook address could not be set
To upgrade the new version of Gitlab, to allow WebHook, you need to find the OutBound Request under the Settings tag in the Admin account of Gitlab. Check Allow Requests to the Local Network from hooks and Services and save the changes to fix the problem.
-
Gradle compile Android project /lib64/libc.so.6: Version ‘glibc_2.14’ not found, the system is CentOS 6.9, the highest supported version of glibc is 2.12, and the development program needs 2.14, so it needs to be upgraded.
/ / check system version of cat/etc/redhat - release / / view the glibc library version strings/lib64 / libc. So. 6 | grep GLIBC_ / / download glibc library And install# downloadWget wget HTTP: / / http://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.gz http://ftp.gnu.org/gnu/glibc/glibc-ports-2.14.tar.gz# decompressionGz tar -xvf glibc-2.14.tar.gz tar -xvf glibc-ports-2.14.tar.gzCreate a related directoryMv glibc-ports-2.14 glibc-2.14/ports mkdir glibc-build-2.14cdGlibc - build - 2.14 /# Generate C compiled environment yum -y install gcc # compiling C ../glibc-2.14/configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin make # Install libc.so just compiled makeinstall # Check the glibc library version strings /lib64/libc.so.6 |grep GLIBC_ Copy the code
-
The last
-
At this point, our continuous integration server has been set up. At this time, you just need to start to submit the code to the branch (generally the main branch) that you set up the trigger before, and Jenkins will help us automatically complete the rest of the repetitive and tedious work such as project construction and deployment, which is time-saving and convenient. If there are any mistakes in the article, please mention them to me, and we can make progress together. If you think my article helps you, please also give me a like or attention.
-
Reference links:
-
Jenkins installation and Use (based on centos 7)
-
Jenkins Maven Spring Boot Git Linux Continuous Integration
-
Jane synchronous address
-