mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-27 17:35:49 +00:00
Update Jenkinsfile
This commit is contained in:
parent
4e0e871b22
commit
4bb827676d
1 changed files with 1 additions and 48 deletions
49
Jenkinsfile
vendored
49
Jenkinsfile
vendored
|
@ -4,54 +4,7 @@ pipeline {
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
steps {
|
steps {
|
||||||
echo 'Running build automation'
|
echo 'Running build automation'
|
||||||
sh './mvnw package'
|
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}\""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue