1、安裝 Publish over SSH 插件
2、將將Jenkins所在機子的public_key添加到待部署服務器的root/.ssh/authorized_keys
3、系統管理設置界面拉到底部設置 Publish over SSH設置Passphrase(生成密碼的時候輸入的密碼)、 Key(Private_key) 、ssh server Name(遠程服務器Ip)、Hostname、UserNane
4、SSH服務器默認端口號是22,點擊高級即可設置Port。
5、配置完成后,點擊 Test Configuration 返回Success即證明Jenkins所在宿主機可以正常鏈接到待部署機。
6、勾選 Send files or execute commands over SSH before the build starts,即在構建開始之前,通過SSH登錄目標服務器進行操作。
勾選 Send files or execute commands over SSH after the build runs, 即在構建完成之后,通過SSH登錄目標服務器進行操作。
7、在任務的構建模塊 Send files or execute commands over SSH 設置Ssh server name 、Exec command
8、測試構建是否成功。