mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-27 09:25:49 +00:00
Update Jenkinsfile
This commit is contained in:
parent
41e1e0645e
commit
a8866c44c3
1 changed files with 57 additions and 10 deletions
65
Jenkinsfile
vendored
65
Jenkinsfile
vendored
|
@ -1,12 +1,59 @@
|
||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
stages {
|
stages {
|
||||||
stage ('Build') {
|
stage('Build') {
|
||||||
steps {
|
steps {
|
||||||
echo 'Running build automation'
|
echo 'Running build automation'
|
||||||
sh './mvnw package'
|
sh './mvnw package'
|
||||||
sh 'java -jar target/*.jar'
|
archiveArtifacts artifacts: 'dist/Petclinic.zip'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
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