Update Jenkinsfile

This commit is contained in:
Oleksandr Butenko 2021-06-13 16:46:41 +03:00 committed by GitHub
parent f0deaf4dac
commit 187d3bd351
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

26
Jenkinsfile vendored
View file

@ -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}\""
}
}
}
}
}
}
}