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

相关推荐
serve the people2 小时前
Elasticsearch(1) could you tell me how to use es if i am a beginner
大数据·elasticsearch·jenkins
ZHW_AI课题组5 小时前
调用阿里云实现文本翻译功能
阿里云·云计算
zahuilg1014 小时前
Mac原生终端SSH一键快捷连接|无需装软件、极简安装、快速上手
macos·ssh·github·终端
程序猿小野15 小时前
在阿里云服务器上安装Docker部署后台项目
阿里云·docker·云计算
开发者联盟league15 小时前
使用jenkins pipeline将项目打包运行在k8s上报错kubectl: Permission denied
java·kubernetes·jenkins
江华森16 小时前
Jenkins 运维管理实战博客大纲
运维·jenkins
X1A0RAN16 小时前
解决jenkins(本机部署或容器部署)安全机制【CSP】问题
jenkins·allure报告
烧饼Fighting16 小时前
Jenkins自动化编译部署Spring Boot项目
spring boot·自动化·jenkins
serve the people16 小时前
Elasticsearch(3) show me some examples
大数据·elasticsearch·jenkins
ZHW_AI课题组16 小时前
使用阿里云 API 实现图像文字识别与校园文档智能分类系统
阿里云·云计算