See on Server Communication by SSH on Ubuntu 16.04
$ mv ~/.ssh/<PRIVATE_KEY_FILE> ~/jenkins/jenkins_home
Jenkins home from Install Docker Jenkins on Ubuntu 16.04
mvn sonar:sonar -Dsonar.host.url=http://<SONARQUBE_SERVER>:9000 -Dsonar.login=<SONARQUBE_USER_TOKEN>
ssh -i $JENKINS_HOME/<PRIVATE_KEY_FILE> \
-o StrictHostKeyChecking=no <REMOTE_USER>@<REMOTE_SERVER> \
'mkdir -p ~/deploy/<PROJECT_NAME>/target'
Copy .jar
scp -i $JENKINS_HOME/<PRIVATE_KEY_FILE> \
-o StrictHostKeyChecking=no \
$JENKINS_HOME/workspace/<PROJECT_NAME>/target/*.jar \
<REMOTE_USER>@<REMOTE_SERVER>:~/deploy/<PROJECT_NAME>/target
Copy Dockerfile
scp -i $JENKINS_HOME/<PRIVATE_KEY_FILE> \
-o StrictHostKeyChecking=no \
$JENKINS_HOME/workspace/<PROJECT_NAME>/Dockerfile \
<REMOTE_USER>@<REMOTE_SERVER>:~/deploy/<PROJECT_NAME>
ssh -i $JENKINS_HOME/<PRIVATE_KEY_FILE> \
-o StrictHostKeyChecking=no \
<REMOTE_USER>@<REMOTE_SERVER> \
'docker rm $(docker stop $(docker ps -a -q --filter ancestor=<DOCKER_IMAGE_NAME> --format=""))'
ssh -i $JENKINS_HOME/<PRIVATE_KEY_FILE> \
-o StrictHostKeyChecking=no \
<REMOTE_USER>@<REMOTE_SERVER> \
'docker image rm <DOCKER_IMAGE_NAME>'
ssh -i $JENKINS_HOME/<PRIVATE_KEY_FILE> \
-o StrictHostKeyChecking=no \
<REMOTE_USER>@<REMOTE_SERVER> \
'docker build -t <DOCKER_IMAGE_NAME> -f ~/deploy/<PROJECT_NAME>/Dockerfile ~/deploy/<PROJECT_NAME>'
ssh -i $JENKINS_HOME/<PRIVATE_KEY_FILE> \
-o StrictHostKeyChecking=no \
<REMOTE_USER>@<REMOTE_SERVER> \
'docker run -d -p <MAP_PORT>:8080 --add-host=<MAP_HOST>:<MAP_IP> --add-host=<MAP_HOST>:<MAP_IP> --name <CONTAINER_NAME> <DOCKER_IMAGE_NAME>'