1.jenkins安装插件 Publish over SSH
详细:系统管理->管理插件->可选插件->搜索[Publish over SSH]-
->安装成功后jenkins自动重启
2.系统管理-系统配置- 配置publish over SSH
image.png3.创建jenkins任务
基本操作略
重要的两个操作:
1.构建 shell 命令
#!/bin/bash
echo '>>> START exec shell'
echo '>>> mvn clean package'
mvn clean package
echo '>>> END exec local shell'
2.构建后操作
image.png
image.png
远程脚本如下:
#!/bin/bash
jarName=magic-genie-admin.jar
dockerName=mg-admin
basePath=/opt/mg-admin
tempJarPath=/opt/mg-admin/temp
echo '>>> START exec remote shell'
echo '>>> stop the docker container'
if sudo docker ps -a|grep -i $dockerName;then
sudo docker stop $dockerName
fi
echo '>>>delete old jar'
sudo rm -r $basePath/$jarName || true
echo '>>>end delete'
echo '>>> cp jar'
sudo cp $tempJarPath/$jarName $basePath/ || true
echo '>>>delete temp dir'
sudo rm -rf $tempJarPath
echo '>>> start the docker container'
sudo docker start $dockerName
echo '>>> END exec shell'
echo '>>>over'
网友评论