Use jenkins to deploy projects
The simple version uses jenkins to deploy projects
Deploy the war package to tomcat
Deploy the existing war package to tomcat (jenkins and tomcat are on the same host)
Click on the new task on the Jenkins homepage
Enter task name
Choose to build a free-style software project and click OK
Add a build step within the build and choose to execute the shell
Enter the execution script
#!/bin/sh tomcat_path=/usr/java/tomcat/tomcat8081 ShutDownTomcat=${tomcat_path}/bin/shutdown.sh StartTomcat=${tomcat_path}/bin/startup.sh echo "============Delete old war package===================" rm ${tomcat_path}/webapps/docker.war echo "============Delete the old folder under tomcat=============" rm -rf ${tomcat_path}/webapps/docker echo "======Copy the compiled war package to tomcat=======" cp /usr/java/project/docker.war ${tomcat_path}/webapps/docker.war echo "====================Close tomcat=====================" ${ShutDownTomcat} echo "================sleep 10s=========================" for i in {1..10} do echo $i"s" sleep 1s done export BUILD_ID=DontKillMe echo "====================Start tomcat=====================" ${StartTomcat} start jar #!/bin/sh jarPath=/usr/java/jar projectJar=/usr/java/project echo "============Delete old jar=============" rm -rf ${projectJar}/demo.jar echo "======Copy the new jar to the running directory=======" cp ${jarPath}/demo.jar ${projectJar}/demo.jar echo "====================Close the jar process=====================" l=`ps -ef|grep -v grep|grep demo|awk '{print $2}'` kill -9 $l echo "================sleep 10s=========================" for i in {1..10} do echo $i"s" sleep 1s done export BUILD_ID=DontKillMe echo "====================Start jar=====================" nohup java -jar ${projectJar}/demo.jar & amp;
Click Build Now on the left
The maven version uses jenkins to deploy projects
Prepare the Linux installation environment
1. Install jdk on linux and configure environment variables
2. Install tomcat on linux and configure environment variables
In the previous article, there is a configuration tutorial for disk and file management http://t.csdnimg.cn/kJmXM
Install and configure git on linux
Install dependent environment
Yum (full name Yellow dog Updater, Modified) is a Shell front-end package manager in Fedora, RedHat and CentOS. Based on RPM package management, it can automatically download and install RPM packages from designated servers, automatically handle dependencies, and install all dependent software packages at once, without the need to download and install them again and again.
yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
2. Delete existing git(!!!)
Don’t forget this step. After configuring the environment variables, if the version of git –version is not the one we installed, you must execute the deletion command again
yum -y remove git
3. Transfer tar to /usr/manually created folder/git and extract it
Git (git-scm.com) Other ways (yum…)
Index of /pub/software/scm/git/ (kernel.org) tar package download
tar -zxvf git-2.9.5.tar.gz
4. Compile
cd git-2.9.5 (enter the decompression directory)
make prefix=/usr/formwork/git all
make prefix=/usr/formwork/git install
1. Compilation may occur
Solution
yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
Re-execute the dependency installation. Here is the configuration of the previous installation dependencies. This has already been installed.
In the previous article Disk and File Management http://t.csdnimg.cn/kJmXM
Remove gcc
Then continue execution after execution
make prefix=/usr/formwork/git all
make prefix=/usr/formwork/git install
5. Configure environment variables into /etc/profile
6.Restart environment variable configuration
source /etc/profile
7. Check git version
git –version
Install and configure maven on linux
1. Official website download link, download .tar.gz
Maven – Download Apache Maven
2. Decompress tar -zxvf
3. Configure environment variables
vi /etc/profile
export MAVEN_HOME=/usr/java/maven/apache-maven-3.5.0
export PATH=$MAVEN_HOME/bin:$PATH
Validate the file source /etc/profile
export MAVEN_HOME=/usr/formwork/apache-maven-3.8.8 export GIT_HOME=/usr/formwork/git export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-1.el7_9.x86_64 export JRE_HOME=$JAVA_HOME export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH:$GIT_HOME/bin:$PATH:$MAVEN_HOME/bin: $PATH
4. Check the maven version number
mvn -v
5. Configure maven download image
Configure ali image
vim /usr/formwork/apache-maven-3.8.8/conf/settings.xml
<mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/repositories/central/</url> </mirror>
6. Install the necessary plug-ins for maven
Remember to configure and download the image before executing it! ! Otherwise you have to wait a long time
mvn help:system
This is rather long
Jenkins security configuration (remember to save and apply)
Global configuration (remember to save and apply)
For the path, just look at the configuration path of the vim /etc/profile environment variable
Start creating a maven project
Download the maven plug-in
Download the git plug-in
1. Create a new task and create a maven project
2. After confirming, slide down to configure the git warehouse
3. Continue to slide down to configure the trigger, triggering every five minutes
4. Compilation options
clean package -U -Dmaven.test.skip=true
BUILD_ID=DONTKILLME echo "Deployed directory and project name" sh /usr/java/test/build.sh echo "success"
The corresponding build.sh (stored in the /usr/java/test/ folder in Linux)
#!/bin/bash echo "Deployed directory and project name" DIR="/usr/java/project" projectName="demo" echo "Application server to be deployed" server_ips="192.168.253.16" #All parameter lists for server_ip in ${server_ips[@]} do echo "Perform backup operation" mkdir -p $DIR/backup/${projectName} if [ -f "$DIR/${projectName}/${projectName}.jar" ];then mv $DIR/${projectName}/${projectName}.jar $DIR/backup/${projectName}/${projectName}-`date " + %Y%m%d_%H%M%S"`.jar fi echo "Copy the jar package to the directory of the target server" cp ${WORKSPACE}/target/*.jar $DIR/${projectName}/${projectName}.jar echo "Target server:$DIR/${projectName}/${projectName}.jar" echo "Connect for publishing operation" #mv /usr/java/test/demo.jar $DIR/backup/${projectName}/${projectName}.jar echo "Start closing jar" l=`ps -ef|grep demo.jar|grep -v grep|awk '{print $2}'` for i in $l do kill -9 $i done sleep 5s echo "start jar" nohup java -jar $DIR/${projectName}/${projectName}.jar --server.port=9999 > release_out.log 2> & amp;1 & amp;start_ok=false done
5. Pay attention to the file path problem
Upload our project at our bound gi warehouse address
Jenkins:
Pull code: git
Packaging: jar
Store the corresponding jar to the specified location
Start building
Both are available, build now
The wait is very long
Solution to build failure
1. Check whether the build.sh file we created has execution permission. If not, chmod -R 755 build.sh
2.vim /usr/formwork/apache-maven-3.8.8/conf/settings.xml
Add s after the http of the ali mirror we configured (maven considers it unsafe and blocks access)
The article has been included in the official knowledge archive Cloud Native Getting Started Skill TreeContinuous Integration and Deployment (Jenkins)Use helm to install Jenkins16851 people are learning the system