mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-12-27 10:57:28 +00:00
Add Jenkins pipeline for building and pushing Docker image
Signed-off-by: Riz Urian <98958099+rizjosel@users.noreply.github.com>
This commit is contained in:
parent
5aafb98125
commit
d0933bf5d7
1 changed files with 45 additions and 0 deletions
45
Jenkinsfile
vendored
Normal file
45
Jenkinsfile
vendored
Normal file
|
|
@ -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
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue