From d0933bf5d77da04a3274919861db58532ca8b90e Mon Sep 17 00:00:00 2001 From: Riz Urian <98958099+rizjosel@users.noreply.github.com> Date: Sat, 27 Dec 2025 00:01:11 +0800 Subject: [PATCH] Add Jenkins pipeline for building and pushing Docker image Signed-off-by: Riz Urian <98958099+rizjosel@users.noreply.github.com> --- Jenkinsfile | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..ad5df8ac5 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,45 @@ +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 + """ + } + } + } + } +}