Jenkins deploy JAR projects, Springboot project deployments __jar

Source: Internet
Author: User
Tags chmod

Explain record Jenkins How to deploy a Jar type project (springboot)

1, configure the environment
The first is to configure JDK, maven, Git, as shown:

2, create the Task (project)


3, source management, Git address, and authentication configuration, click Add, add user name and password



4, the key is the script

#!/bin/bash
Cd/deploy_cmp_script
echo "Execute Shell Start"
SH stop.sh
SH replace.sh
echo "Execute Shell Finish"
chmod 777/deploy_cmp_script/startup.sh
Build_id=dontkillme nohup/deploy_cmp_script/startup.sh &

Three contents of a file

==================stop.sh===start=======================

#! will apply to stop
#!stop.sh
#!/bin/bash
Cd/deploy_cmp_script
echo "Stopping Springboot application for CMP"
Ls
Pid= ' Ps-ef | grep Cmp-0.0.1-snapshot.jar | Grep-v grep | awk ' {print $} '
If [-N "$pid"]
Then
#!kill-9 forced termination
echo "kill-9 pid:" $pid
Kill-9 $pid
Fi

==================stop.sh===end =======================


==================replace.sh===start=======================

Jar_name=cmp-0.0.1-snapshot.jar
#! a compiled jar package store address
File_path=~/.jenkins/workspace/cmp/target
#! Replace the existing jar with the new jar package after it is backed up
File= "/deploy_cmp/cmp-0.0.1-snapshot.jar"
If [-F "$file]"
Then
Mv/deploy_cmp/cmp-0.0.1-snapshot.jar/deploy_cmp_backup/cmp-0.0.1-snapshot.jar. ' Date +%Y%m%d%H%M%S '
Fi
CP ~/.jenkins/workspace/cmp/target/cmp-0.0.1-snapshot.jar/deploy_cmp
==================replace.sh===end =======================


==================startup.sh===start=======================

Ehco "Grant Current user rights"
chmod 777/deploy_cmp/cmp-0.0.1-snapshot.jar
echo "Execute ..."
cd/deploy_cmp
Java-jar Cmp-0.0.1-snapshot.jar
echo "**********************cmp on Jenkins started*************************"
==================startup.sh===end =======================


After the application is saved, build the project directly.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.