Jenkins使用Publish Over SSH插件远程部署程序到阿里云服务器

前言

使用Jenkins远程构建springboot服务到阿里云上,Jenkins版本:Version 2.462.1

1、准备

在可选插件中,搜索Maven Integration ,Gitlab和 Publish Over SSH 三个插件:

如果需要多用户管理那就安装:Role-based Authorization Strategy插件即可

2、配置Publish Over SSH服务

如果这块出现问题,请查看下面问题解决方案

3、项目脚本配置

脚本:

bash 复制代码
source /etc/profile
project=springboot-rest.jar
dir=/home/project/app/

if [ ! -d "$dir" ]; then
    mkdir -p "$dir"
fi

api_id=$(ps -ef | grep 9099 | grep -v "grep" | grep "$dir$project" | awk '{print $2}')
echo $api_id

for id in $api_id
do
  kill -9 $id
echo "killed $id"
done

nohup java -Xms1G -Xmx1G -XX:PermSize=32m -XX:MaxPermSize=512m -jar "$dir$project" --spring.profiles.active=prod --server.port=9099 > $dir/nohup.out 2>&1 &

基本到这就大功告成了。

如果在构建中出现问题,可以勾选这个打印详细的远程问题进行定位解决,

问题解决方案

问题1:jenkins.plugins.publish_over.BapPublisherException: Failed to connect and initialize SSH connection. Message: [Failed to connect session for config [aly-ssh]. Message [Algorithm negotiation fail: algorithmName="server_host_key" jschProposal="ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-512,rsa-sha2-256" serverProposal="ssh-rsa,ssh-dss"]]

解决方案:

在启动时增加配置参数即可:

1 如果是war包直接启动的:直接在java -jar 后面添加这两个参数

bash 复制代码
-Djsch.client_pubkey=ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-512,rsa-sha2-256  
-Djsch.server_host_key=ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-512,rsa-sha2-256

2 如果是exe启动的(windows的msi安装版是在服务启动的),那就找到jenkins目录下的jenkins.xml,找到下的标签jvm参数后

参考资料:
https://blog.csdn.net/t0404/article/details/136206576
https://developer.aliyun.com/article/1312890
https://blog.csdn.net/suo082407128/article/details/116239286
https://blog.csdn.net/m0_58943936/article/details/135368557
https://blog.csdn.net/JasonWeng/article/details/113574958
https://my.oschina.net/mmuuyyuu/blog/5544039
https://www.cnblogs.com/jxxiaocao/p/12691289.html

相关推荐
一念一花一世界2 小时前
Jenkins vs GitLab CI/CD vs Arbess,CI/CD工具一文纵评
ci/cd·gitlab·jenkins·arbess
YuanDaima20483 小时前
GitHub 与 Gitee 多平台 SSH Key 配置指南
gitee·开源·ssh·github·开源软件·key·免密登录
Fluency-114 小时前
ubuntu中ssh连接root用户
linux·ubuntu·ssh
安冬的码畜日常4 小时前
【JUnit实战3_21】第十二章:JUnit 5 与主流 IDE 的集成 + 第十三章:用 JUnit 5 做持续集成(上):在本地安装 Jenkins
junit·eclipse·jenkins·intellij idea·持续集成·junit5·netbeans
matrixlzp4 小时前
Jenkins 实战4:集群配置与分布式构建
运维·jenkins
行思理5 小时前
本地用docker开发的php 程序如何部署到阿里云的ecs上
阿里云·docker·容器
潮汐退涨月冷风霜7 小时前
VSCode SSH远程连接失败 最速解决方案
ide·vscode·ssh
2021黑白灰9 小时前
windows11 vscode ssh远程linux服务器/虚拟机 免密登录
linux·服务器·ssh
TMT星球10 小时前
IDC报告:阿里云市场份额升至26.8%,连续5季度上涨
阿里云·云计算
matrixlzp11 小时前
Jenkins 实战3:Jenkins + habor + docker 自动化部署
运维·jenkins