Jenkins deploys Java projects to remote Linux

Source: Internet
Author: User

(1) New Java Project (MAVEN build)

(2) New Jenkins Project

(3) Download plugin Publish over SSH

(4) Configure publish over SSH (click System Management---system settings)

(5) Enter the System configuration page, the previous configuration remains the same, pull down to publish over SSH configuration

Passphrase: Here is your host generated SSH key Passphrase value, if you have been enter, here is empty, nothing to write, blank on the line

Path to key: This is where the host key is written, remember that it is Id_ras, not id_ras.pub

Key: If you do not write the host key location above, here will directly copy the key content--paste it over

Name: You can take the name yourself, I will take the user name @ host number. com

Hostname: The host IP must be written here

Username: User name is usually root

(6) Continue to the following configuration: After the configuration here, choose Testconfiguration, not written wrong will appear success

(7) After the appearance of success, the configuration is successful, and then you can start the configuration of the project, the previous configuration is not changed, after adding the build operation here Configuration Select Send Buiild artifacets over SSH

(8) Enter the configuration

Name: is the name of the publish over SSH configuration that was just inside the system setup

Source Filew: The location of the project Jar package, which Jenkins automatically packed and compiled in the target directory

Remove prefix: Remove prefix target

Remote directory: directory where the project jar package is stored remotely

Exec Command: The shell script executed #这里和部署到本地的脚本类似

Script content:

#!/bin/sh
cd/root/home/program/pro_java/ #进入项目jar包存放目录

#得到进程ID Pid,kill The process
pid= ' cat/root/home/program/pro_java/pid ' #得到该目录下 the process ID in the PID file
if [-N "$pid"]
Then
echo "kill-9 pid:" $pid
kill-9 $pid #kill该进程
fi

#执行jar, and suspend the process, save the process ID to the PID file
echo "Execute shell Finish"
Build_id=dontkillme nohup Java-jar/root/home/program/pro_java/jenkins_jar.jar & Echo "$!" > PID #执行项目j AR package, suspend the process, and then write the process ID to the PID file in the current directory

You can then complete the build

Jenkins deploys Java projects to remote Linux

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.