Update Jenkinsfile

This commit is contained in:
Oleksandr Butenko 2021-06-13 12:23:26 +03:00 committed by GitHub
parent 4e0e871b22
commit 4bb827676d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

49
Jenkinsfile vendored
View file

@ -4,54 +4,7 @@ pipeline {
stage('Build') {
steps {
echo 'Running build automation'
sh './mvnw package'
}
}
stage('Build Docker Image') {
when {
branch 'main'
}
steps {
script {
app = docker.build("sprientera/train-schedule")
app.inside {
sh 'echo $(curl localhost:8080)'
}
}
}
}
stage('Push Docker Image') {
when {
branch 'main'
}
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'sprientera') {
app.push("${env.BUILD_NUMBER}")
app.push("latest")
}
}
}
}
stage ('DeployToProduction') {
when {
branch 'master'
}
steps {
input 'Deploy to Production'
milestone(1)
withCredentials ([usernamePassword(credentialsId: 'webserver_login', usernameVariable: '', passwordVariable: 'USERPASS')]) {
script {
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@${env.prod_ip} \"docker pull <DOCKER_HUB_USERNAME>/train-schedule:${env.BUILD_NUMBER}\""
try {
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@${env.prod_ip} \"docker stop train-schedule\""
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@${env.prod_ip} \"docker rm train-schedule\""
} catch (err) {
echo: 'caught error: $err'
}
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@${env.prod_ip} \"docker run --restart always --name train-schedule -p 8080:8080 -d <DOCKER_HUB_USERNAME>/train-schedule:${env.BUILD_NUMBER}\""
}
}
sh './mvnw package
}
}
}