阿里爸爸2019-12 升級的
Alibaba Cloud ToolKitidea插件終于支持完整的scp和remote 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了。
- 配置jar
Edit Configurations -> new Configuration -> JAR Application

2.配置scp.jar

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

合并兩步操作

- 配置完畢后
Run it!

控制臺查看
