1.首先在宿主机安装sshpass
2.把物理机的sshpass复制到容器中
which sshpass
cp $(which sshpass) /usr/local/app/
docker cp sshpass 容器id:/usr/local/bin/sshpass
3.在jenkinsfile中添加
#在stages中添加stage
stage('部署TEST服务'){steps{sh "sshpass -p root1234 scp -o StrictHostKeyChecking=no -r /var/jenkins_home/workspace/one-code-all/dist/static/" //一定得先删除,mv命令不能覆盖sh "sshpass -p root1234 ssh -o StrictHostKeyChecking=no afp@10.55.120.66 rm -rf /opt/app/middles/nginx-1.20.2/html/afp_bak"sh "sshpass -p root1234 ssh -o StrictHostKeyChecking=no afp@10.55.120.66 mv /opt/app/middles/nginx-1.20.2/html/afp /opt/app/middles/nginx-1.20.2/html/afp_bak"sh "sshpass -p root1234 ssh -o StrictHostKeyChecking=no afp@10.55.120.66 mv /opt/app/middles/nginx-1.20.2/html/static /opt/app/middles/nginx-1.20.2/html/afp"}
}