This article mainly explains the use of Jenkins to implement the automated deployment of spring boot projects:
•1. Backend technical architecture: Spring boot 1.4.2.RELEASE +Mybatis 3+ Redis+ Mysql 5.6+JDK8;
•2. Code building tools: maven 3.3;
•3. Source code hosting tool: Gitlab;
•4. Use maven's docker plug-in to package it into a docker image to deploy the project in the docker container;
•5. The server is Alibaba Cloud's ECS;
1. Install Jenkins
1. The method of installing Jenkins on Alibaba Cloud Server is as follows: Link
2. Installation command:
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.reposudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.keysudo yum install jenkins
1. Start/stop Jenkins:
sudo service jenkins start/stop/restartsudo chkconfig jenkins on
1. After the installation is completed, the default port is 8080. You can view the administrator password in the startup log. The log path is: /var/log/jenkins/jenkins.log;
2. After installing Jenkins, starting Jenkins requires a Java environment. If you start an error, remember to check whether the server has JRE installed;
3. At this time, Jenkins cannot be accessed through IP and ports, and a firewall must be configured:
vim /etc/yum.repos.d/jenkins.repo #Require root permission # Write the following content in the file: firewall-cmd --permanent --new-service=jenkinsfirewall-cmd --permanent --service=jenkins --set-short="Jenkins Service Ports"firewall-cmd --permanent --service=jenkins --set-description="Jenkins service firewalld port exceptions"firewall-cmd --permanent --service=jenkins --add-port=8080/tcpfirewall-cmd --permanent --add-service=jenkinsfirewall-cmd --zone=public --add-service=http --permanentfirewall-cmd --reload#Save Exit firewall-cmd --list-all
So far, Jenkins has been basically installed, and you can access it by entering ip:prot in the browser.
2. Configure projects that need to be deployed in Jenkins
1. Install the required plugins in Jenkins, including git, maven and other related plugins;
Configure git and auto-install maven;
1. Create a new task:
This option will not be available without installing the maven plugin
3. See screenshot for specific configuration:
After saving and exiting, you can basically build it. After waiting for the long jar download process, you will find that the project has been successfully built.
3. Docker deployment scripts and commands:
1. The build script is as follows (bulid.sh):
#! /bin/shcd /var/jenkins_home/workspace/authority_system_backendecho "mvn install"mvn clean install -Pdev -Dmaven.test.skip=trueecho "delete project"docker rm -f authority_system_backend_devecho "start project"docker run -d --name='authority_system_backend_dev' authority_system_backend_dev:latest
2. After successful construction, see the following figure:
The blue dot indicates that the construction was successful, and the small sun indicates the probability of the construction being successful. The higher the probability, the clearer the weather.
Summarize
The above is the spring boot project introduced by the editor to you using Jenkins to achieve automated deployment. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!