四.docker-compose中jenkins配置远程部署

jenkins远程部署

安装Publish over SSH插件

配置

系统管理-->系统设置-->publish over ssh

ssh生成(小知识)

$ ssh-keygen -t rsa -C '[email protected]'
# 3次回车
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:cF2NVKakpPiYrqrBlxUkzhtoYG8e9wXQOjSZ2oarbEc [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|.. . o=.  ..++o  |
|o = o= o.+ +.o.  |
| o B=o= o.o .    |
|. oo==o*.        |
|   oo.+.S        |
|.  Eo.           |
|o.oo  .          |
| =.. .           |
|o.o..            |
+----[SHA256]-----+
$ cd .ssh/
authorized_keys  id_rsa  id_rsa.pub

配置远程部署

配置远程部署服务器.png

注意:用户名密码一定要填对!

任务配置远程构建环境

jenkins配置远程构建环境.png
启动脚本
app_name=$1
port=8888
echo $port
pid=$(netstat -nlp | grep :$port | awk '{print $7}' | awk -F"/" '{ print $1 }')
echo $pid
if [  -n  "$pid"  ];  then
    echo '正在停止端口'$port',pid='$pid
    kill  -9  $pid;
fi
echo 正在启动程序...${app_name}
nohup java -jar [-Dspring.profiles.active=DEV] ${app_name} -Xmx256 >&1 &
# tail -f (日志路径)
# 执行脚本命令
sh ./start.sh (程序名)

你可能感兴趣的:(四.docker-compose中jenkins配置远程部署)