mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:35:49 +00:00
Add Jenkinsfile
This commit is contained in:
parent
324c795b1f
commit
ff23106794
1 changed files with 54 additions and 0 deletions
54
Jenkinsfile
vendored
Normal file
54
Jenkinsfile
vendored
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
|
||||||
|
environment {
|
||||||
|
// Define environment variables
|
||||||
|
DOCKER_REGISTRY = "docker.io"
|
||||||
|
DOCKER_IMAGE = "mmarcetic/main"
|
||||||
|
DOCKER_CREDENTIALS = "Docker_hub"
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('Checkout') {
|
||||||
|
steps {
|
||||||
|
// Checkout the code from the repository
|
||||||
|
checkout scm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build Docker Image') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
// Build the Docker image
|
||||||
|
sh 'docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest .'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Push Docker Image') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
//Login to the Docker repository
|
||||||
|
docker.withRegistry('https://${DOCKER_REGISTRY}', "${DOCKER_CREDENTIALS}") {
|
||||||
|
// Push the Docker image to the registry
|
||||||
|
sh 'docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
// Clean up Docker images after the job is done
|
||||||
|
sh 'docker rmi ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest || true'
|
||||||
|
}
|
||||||
|
success {
|
||||||
|
echo 'Docker image built and pushed successfully.'
|
||||||
|
}
|
||||||
|
failure {
|
||||||
|
echo 'Pipeline failed!'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue