spring-petclinic/Jenkinsfile
Riz Urian d0933bf5d7
Add Jenkins pipeline for building and pushing Docker image
Signed-off-by: Riz Urian <98958099+rizjosel@users.noreply.github.com>
2025-12-27 00:01:11 +08:00

45 lines
1.2 KiB
Groovy

pipeline {
triggers {
githubPush()
}
agent any
environment {
APP_NAME = "petclinic"
DOCKER_USER = "rizjosel"
IMAGE_TAG = "${BUILD_NUMBER}"
IMAGE_NAME = "${DOCKER_USER}/${APP_NAME}:${IMAGE_TAG}"
}
stages {
stage('List Workspace') {
steps {
sh 'ls -l'
}
}
stage('Build Application (Gradle)') {
steps {
sh './gradlew clean build -x test'
archiveArtifacts artifacts: 'build/libs/*.jar', fingerprint: true
}
}
stage('Build Docker Image') {
steps {
sh "docker build -t ${IMAGE_NAME} ."
}
}
stage('Docker Push') {
steps {
withCredentials([string(credentialsId: 'dockerhub-creds', variable: 'DOCKER_TOKEN')]) {
sh """
echo \$DOCKER_TOKEN | docker login -u ${DOCKER_USER} --password-stdin
docker push ${IMAGE_NAME}
docker logout
"""
}
}
}
}
}