IDEA一鍵部署到開發(fā)服務(wù)器

阿里爸爸2019-12 升級的Alibaba Cloud ToolKit idea插件終于支持完整的scpremote script功能了,大家省事的話,不用看以下教程了,直接去Idea -> Settings -> Plugins 中找到它吧。

開始

將服務(wù)部署到開發(fā)服務(wù)器上一般步驟:第一步需要將你的war包(或者其他)scp到服務(wù)器的指定位置上;第二步在將服務(wù)通過一定的shell命令執(zhí)行部署的步驟。

jenkins可以完美的處理以上步驟,不用jenkins還有其他輕量級的方法處理嗎?

也是對應(yīng)的兩步:第一步得有能自動化scp的工具。第二步有自動化執(zhí)行遠(yuǎn)程腳本的工具。如果能將這兩步集成到IDEA中變成一個按鈕的操作,那就非常舒服了。

工具

scp工具

首先考慮到的就是用scp命令,linux環(huán)境可以直接用自帶的scp命令,Windows環(huán)境網(wǎng)上也有相應(yīng)的scp.exe,但是命令行沒有現(xiàn)成自動輸入密碼的解決方案,配置成本高。

何不利用java跨平臺特性的手寫一個scp.jar呢?

說干就干

https://gitee.com/zkdcloud.cn/scp/releases

java -jar .\scp-1.0.0.jar -help

usage: scp -help
 -d,--dst_path <arg>   the dstPath of remote
 -h,--host <arg>       the host of remote server
 -help                 usage help
 -P,--port <arg>       the port of remote server
 -p,--password <arg>   the password of remote server
 -s,--src_path <arg>   the srcPath of local
 -u,--user <arg>       the user of remote server

非常簡單的scp工具就誕生了,包含scp所需要的基本參數(shù),執(zhí)行命令如下:

java -jar .\scp-1.0.0.jar -s "D:\abc-project\target\abc.war" -h "192.168.27.112" -u "root" -p "111111" -d "/tmp/abc.war"

shell-exec工具

遠(yuǎn)程執(zhí)行shell命令的工具同理。

https://gitee.com/zkdcloud.cn/shell-exec/releases

java -jar .\shell-exec-1.0.0.jar -help
Missing required options: h, u, p, c
usage: scp -help
 -c,--command <arg>    will exec command
 -h,--host <hello>     the host of remote server
 -help                 usage help
 -P,--port <arg>       the port of remote server
 -p,--password <arg>   the password of remote server
 -u,--user <arg>       the user of remote server
java -jar .\shell-exec-1.0.0.jar -c "mv /tmp/abc.war /home/tomcat/webapps/ && /home/tomcat/bin/startup.sh" -h 192.168.27.112 -u root -p 111111

IDEA上一鍵部署

有了這兩個工具,剩下的就是集成進(jìn)去IDEA了。

  1. 配置jar Edit Configurations -> new Configuration -> JAR Application
image

2.配置scp.jar


image

3.同理配置shell-exec.jar

4.構(gòu)建新增配置Edit Configurations -> new Configuration -> Compound,將這兩步操作合成一步操作
添加compound

image

合并兩步操作


image
  1. 配置完畢后 Run it!
image

控制臺查看


image
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容