spring-petclinic/Jenkinsfile

51 lines
1.4 KiB
Text
Raw Normal View History

2025-02-12 09:00:29 +00:00
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
2025-03-06 15:04:20 +00:00
def gitCommit = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
sh "docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${gitCommit} ."
2025-02-12 09:00:29 +00:00
}
}
}
stage('Push Docker Image') {
steps {
script {
2025-03-06 15:04:20 +00:00
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}"
2025-02-12 09:00:29 +00:00
}
}
}
}
}
post {
success {
echo 'Docker image built and pushed successfully.'
}
failure {
echo 'Pipeline failed!'
}
}
}