springBoot integration with Jenkins for automated deployment
1.First install jenkins
importing source&&yum erect
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.reposudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.keyyum install jenkins
Notes before starting Jenkins after installation to facilitate later operation and less pit picking.
The default is that Jenkins is using the
Jenkins
user to start, but this user is not currently granted privileges by the system, here we change the start user to
root
The default port of Jenkins is 8080, which conflicts with the default port of tomcat, so let's change the default port as well.
vi /etc/sysconfig/jenkins -------------------------------- find JENKINS_USER harmonyJENKINS_PORT , Modify toroot and the port you need JENKINS_USER="root"JENKINS_PORT="8081"
Once the changes are complete you can start Jenkins
service jenkins start service jenkins stop service jenkins restart
Once started, check to see if the firewall is open for the port set by Jenkins
Then you can access it by entering the ip+port number in your browser, for example: http:192.168.31.101:8081, then you will see this.
Follow the steps
It doesn't matter if you fail, just try again
The plugins that need to be installed are just installed by default
Part 2: Jenkins integration with springboot
Once in Jenkins, add the task
Select the maven project, if there is no maven project, you can go to the plugin management to download, before integrating this part, the server should be installed git, maven, git version preferably greater than 1.7, and jdk, and then in the global tools configuration in Jenkins to configure the path of jdk and maven:.
After creating a task: go to Task Configuration
Jenkins pulls the code off the branch you paired and copies it to the folder specified for execution, then executes the startup, shell script.
#!/bin/bash #export BUILD_ID=dontKillMe That's an important sentence., This designates the, It is only after the project is started that it will not beJenkins kill。export BUILD_ID=dontKillMe# Specify the final compiledjar Location of storagewww_path=/var/codespace/test/#Jenkins Compiled injar locationjar_path=/var/lib/jenkins/jobs/shaw/workspace/shaw-web/target/#Jenkins Compiled injar name (of a thing)jar_name=shaw.jar# Get the compiled process runningID, It is easy to kill the previous processes when we redeploy the projectpid=$(cat /var/codespace/test/shaw-test-web.pid)# Go to the specified compiledjar locationcd $# Compile the compiledjar Copy to the final location specifiedcp $/$ $# Go to the last designated storagejar locationcd $# Kill project processes that may have been started previouslykill -9 $# launchjar, designateSpringBoot ofprofiles because oftest, Backstage activationjava -jar -Dspring.profiles.active=test $ &# will processID deposit intoshaw-web.pid fileecho $! > /var/codespace/test/shaw-test-web.pid
Finally save this configuration
As a final step, run springboot