mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-18 05:25:50 +00:00
Update Jenkinsfile
Signed-off-by: prankumargrid <prankumar@griddynamics.com>
This commit is contained in:
parent
96c8f864d0
commit
d2f5f2445d
1 changed files with 48 additions and 13 deletions
61
Jenkinsfile
vendored
61
Jenkinsfile
vendored
|
@ -7,7 +7,8 @@ pipeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
IMAGE_NAME = 'prankumar313-main'
|
IMAGE_NAME = "spring-petclinic"
|
||||||
|
DOCKERHUB_USER = "prankumar313" // Change to your Docker Hub username
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
|
@ -16,29 +17,63 @@ pipeline {
|
||||||
sh '''
|
sh '''
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install -y docker.io
|
apt-get install -y docker.io
|
||||||
|
docker --version
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build Docker Image') {
|
stage('Checkstyle') {
|
||||||
|
when {
|
||||||
|
expression { env.BRANCH_NAME != 'main' }
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh './gradlew checkstyleMain checkstyleTest'
|
||||||
|
archiveArtifacts artifacts: '**/build/reports/checkstyle/*.xml', allowEmptyArchive: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Test') {
|
||||||
|
when {
|
||||||
|
expression { env.BRANCH_NAME != 'main' }
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh './gradlew test'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build (No Tests)') {
|
||||||
|
when {
|
||||||
|
expression { env.BRANCH_NAME != 'main' }
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh './gradlew build -x test'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build & Push Docker Image') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
COMMIT = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
COMMIT = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
||||||
sh "docker build -t ${IMAGE_NAME}:${COMMIT} ."
|
IMAGE_TAG = "${DOCKERHUB_USER}/${env.BRANCH_NAME == 'main' ? 'main' : 'mr'}:${COMMIT}"
|
||||||
|
|
||||||
|
sh """
|
||||||
|
docker build -t ${IMAGE_TAG} .
|
||||||
|
"""
|
||||||
|
|
||||||
|
withCredentials([usernamePassword(credentialsId: 'dockerhub-creds', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
|
||||||
|
sh """
|
||||||
|
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
|
||||||
|
docker push ${IMAGE_TAG}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Push to Docker Hub') {
|
post {
|
||||||
steps {
|
always {
|
||||||
withCredentials([usernamePassword(credentialsId: 'dockerhub-creds', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
|
cleanWs()
|
||||||
sh '''
|
|
||||||
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
|
|
||||||
docker tag ${IMAGE_NAME}:${COMMIT} ${DOCKER_USER}/${IMAGE_NAME}:${COMMIT}
|
|
||||||
docker push ${DOCKER_USER}/${IMAGE_NAME}:${COMMIT}
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue