發布java項目的步驟:
- 拉取代碼并打包
- mvn clean package
- 備份目標服務器上已有的要發布項目
- 將包傳到目標服務器的webapss目錄中
- 需做免密登錄
- 重啟目標服務器的tomcat服務
- 修改項目的配置
- 重啟目標服務器的tomcat服務
項目要求:
兩臺主機上分別安裝jenkins,tomcat
jenkins主機上操作
#兩臺主機做免密登錄 [root@localhost ~]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. 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:0zPiM+3ypvmYPisJbeL8LhA2QApiAVqwF9C+gyASonU [email protected] The key's randomart image is: +---[RSA 3072]----+ |OB+ | |Xoo.E | |*=.. | |=.= . | |+o + . S + | |. + o o. + o | | = + .+ . | | + o oB. | | +ooBO+ | +----[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" The authenticity of host '192.168.8.131 (192.168.8.131)' can't be established. ECDSA key fingerprint is SHA256:WbxvLgdwExwRlMT4gaAC1bVyIovZnAwwX1DX8dv6Rs0. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes /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 ~]# yum -y install git maven
新建項目
拉取代碼鏈接:https://gitee.com/neawalke/tomcat-java-demo.git
當拉取的代碼是私有倉庫
測試訪問頁面
到此這篇關于通過jenkins發布java項目到目標主機上的文章就介紹到這了,更多相關jenkins發布java項目內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/NeaWalke/article/details/120844558