environment
// Turn off firewall selinux //Install the packaging command, git [root@jenkins ~]# yum -y install maven [root@jenkins ~]# yum -y install git //Configure password-free login [root@localhost ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:npcyZyHpOPmqGL1nbpZRj7UYULZxJhvNIcDg2G9Qvso [email protected] The key's randomart image is: +---[RSA 3072]----+ | .oooBo+. | | + oo. Xo | | . + ..o | | o .o.. | | +.S*.. | | o o.=oooo | | . E +o* = | | o .*o * | | . oBo.. | +----[SHA256]-----+ [root@localhost ~]# ssh-copy-id [email protected] /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys [email protected]'s password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh '[email protected]'" and check to make sure that only the key(s) you wanted were added. [root@localhost ~]# ssh [email protected] Last login: Wed Oct 20 11:03:43 2021 from 192.168.216.200 [root@localhost ~]# exit LogoutConnection to 192.168.216.215 closed. Enter the Jenkins terminal pipeline agent any stages { stage('Build') { steps { // Get some code from a GitHub repository git 'https://gitee.com/forgotten/tomcat-java-demo.git' #Download the package and make sure the git command is available on the host // Run Maven on a Unix agent. sh "mvn -Dmaven.test.failure.ignore=true clean package" #Package into war packagesh "mv target/ly-simple-tomcat-0.0.1-SNAPSHOT.war target/myapp.war" #Change package name// To run Maven on a Windows agent, use // bat "mvn -Dmaven.test.failure.ignore=true clean package" } } stage("publish"){ steps{ sh "ssh [email protected] 'tar -Jcf /opt/backup/webapps-\$(date +%Y-%m%d).tar.xz /usr/local/tomcat/webapps/*'" #Backup the original projectsh "scp target/myapp.war [email protected]:/usr/local/tomcat/webapps/" #Transfer the package to the target hostsh "ssh [email protected] '/usr/local/tomcat/bin/catalina.sh stop;sleep 3;/usr/local/tomcat/bin/catalina.sh start'" #Restart the generated project} } } } Go to the target host to verify Manual deployment //Turn off firewall, selinux // Make sure the git command exists and pull the deployed project package [root@jenkins opt]# git clone https://gitee.com/forgotten/tomcat-java-demo.git Cloning into 'tomcat-java-demo'... remote: Enumerating objects: 558, done. remote: Counting objects: 100% (558/558), done. remote: Compressing objects: 100% (316/316), done. remote: Total 558 (delta 217), reused 558 (delta 217), pack-reused 0 Receiving objects: 100% (558/558), 5.08 MiB | 673.00 KiB/s, done. Processing delta: 100% (217/217), done. [root@jenkins opt]# ls tomcat-java-demo //Package, make sure the mvn command exists [root@jenkins opt]# cd tomcat-java-demo/ [root@jenkins tomcat-java-demo]# ls db Dockerfile LICENSE README.md deploy.yaml jenkinsfile pom.xml src // All files with pom.xml are packaged with mvn [root@jenkins tomcat-java-demo]# mvn clean package [root@jenkins tomcat-java-demo]# mv target/ly-simple-tomcat-0.0.1-SNAPSHOT.war target/myapp.war [root@jenkins tomcat-java-demo]# ls target/ classes ly-simple-tomcat-0.0.1-SNAPSHOT maven-status generated-sources maven-archiver myapp.war // Make sure there is a password-free login, start the server-side tomcat through ssh, and then pass the package to be deployed [root@jenkins tomcat-java-demo]# scp target/myapp.war [email protected]:/usr/local/tomcat/webapps/ //tomcat will automatically decompress, and after a while you can enter the corresponding directory of the website to see the newly deployed project This is the end of this article about using Jenkins to deploy a project to another host. For more information about deploying a Jenkins project to another host, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How Web Designers Create Images for Retina Display Devices
>>: Use of marker tags in CSS list model
If you use docker search centos in Docker Use doc...
Table of contents Preface Connection Management A...
I encountered a strange network problem today. I ...
Normally, when a deadlock occurs, the connection ...
Using the knowledge of CSS variables, I will dire...
Table of contents 1. beforeCreate and created fun...
In daily work, we sometimes run slow queries to r...
1. Type introduction 1.1 Domain-based virtual hos...
1. An error (1064) is reported when using mysqldu...
Table of contents Install sakila Index Scan Sort ...
In front-end development, $ is a function in jQue...
As a software developer, you must have a complete...
The result (full code at the bottom): The impleme...
Preface In the Linux kernel, netfilter is a subsy...
Previously, the images we used were all pulled fr...