From 187d3bd3510872a01cc05799bf807dee6c442a26 Mon Sep 17 00:00:00 2001 From: Oleksandr Butenko <58562385+sprientera992@users.noreply.github.com> Date: Sun, 13 Jun 2021 16:46:41 +0300 Subject: [PATCH] Update Jenkinsfile --- Jenkinsfile | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7709ed50b..3be9bc76d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -39,5 +39,29 @@ pipeline { } } } + + + + stage ('DeployToProduction') { + when { + branch 'main' + } + steps { + input 'Deploy to Production' + milestone(1) + withCredentials ([usernamePassword(credentialsId: 'cloud_user', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { + script { + sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@${env.prod_ip} \"docker pull sprientera/pet:${env.BUILD_NUMBER}\"" + try { + sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@${env.server_api \"docker stop pet\"" + sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@${env.server_api \"docker rm pet\"" + } catch (err) { + echo: 'caught error: $err' + } + sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@${env.server_api \"docker run --restart always --name pet -p 80:80 -d sprientera/pet:${env.BUILD_NUMBER}\"" + } + } + } + } } -} +}