mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-05-28 13:59:37 +00:00
50 lines
1.4 KiB
Groovy
50 lines
1.4 KiB
Groovy
pipeline {
|
|
agent any
|
|
|
|
environment {
|
|
// Define environment variables
|
|
DOCKER_REGISTRY = "docker.io"
|
|
DOCKER_IMAGE = "mmarcetic/main"
|
|
}
|
|
|
|
stages {
|
|
stage('Checkout') {
|
|
steps {
|
|
// Checkout the code from the repository
|
|
checkout scm
|
|
}
|
|
}
|
|
|
|
stage('Build Docker Image') {
|
|
steps {
|
|
script {
|
|
// Build the Docker image
|
|
def gitCommit = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
|
sh "docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${gitCommit} ."
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Push Docker Image') {
|
|
steps {
|
|
script {
|
|
def gitCommit = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
|
withCredentials([usernamePassword(credentialsId: "docker-login", usernameVariable: "DOCKER_USER", passwordVariable: "DOCKER_PASSWORD")]) {
|
|
sh "docker login -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}"
|
|
sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${gitCommit}"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
success {
|
|
echo 'Docker image built and pushed successfully.'
|
|
}
|
|
failure {
|
|
echo 'Pipeline failed!'
|
|
}
|
|
}
|
|
}
|
|
|