DevOps系列---【jenkinsfile使用sshpass发送到另一台服务器】

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 [email protected] rm -rf /opt/app/middles/nginx-1.20.2/html/afp_bak"
      sh "sshpass -p root1234 ssh -o StrictHostKeyChecking=no [email protected] 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 [email protected] mv /opt/app/middles/nginx-1.20.2/html/static /opt/app/middles/nginx-1.20.2/html/afp"
    }
}

你可能感兴趣的:(devops,服务器,java,运维,开发语言)