mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:15:50 +00:00
Update Jenkinsfile
Signed-off-by: prankumargrid <prankumar@griddynamics.com>
This commit is contained in:
parent
8ce35bef8d
commit
ea795ed756
1 changed files with 45 additions and 66 deletions
111
Jenkinsfile
vendored
111
Jenkinsfile
vendored
|
@ -1,71 +1,50 @@
|
||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
environment {
|
||||||
environment {
|
DOCKER_IMAGE = "prankumar313"
|
||||||
DOCKERHUB_CREDENTIALS = credentials('dockerhub-credentials')
|
COMMIT = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
||||||
IMAGE_NAME_MAIN = "prankumar313/main"
|
}
|
||||||
IMAGE_NAME_MR = "prankumar313/mr"
|
stages {
|
||||||
|
stage('Checkstyle') {
|
||||||
|
when {
|
||||||
|
not { branch 'main' }
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh './gradlew checkstyleMain checkstyleTest'
|
||||||
|
archiveArtifacts artifacts: '**/build/reports/checkstyle/*.xml', allowEmptyArchive: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stage('Test') {
|
||||||
stage('Check Git Branch') {
|
when {
|
||||||
steps {
|
not { branch 'main' }
|
||||||
script {
|
}
|
||||||
BRANCH_NAME = env.BRANCH_NAME ?: sh(script: 'git rev-parse --abbrev-ref HEAD', returnStdout: true).trim()
|
steps {
|
||||||
IS_MR = BRANCH_NAME != 'main'
|
sh './gradlew test'
|
||||||
COMMIT_HASH = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Checkstyle') {
|
|
||||||
when {
|
|
||||||
expression { IS_MR }
|
|
||||||
}
|
|
||||||
steps {
|
|
||||||
sh './gradlew checkstyleMain'
|
|
||||||
}
|
|
||||||
post {
|
|
||||||
always {
|
|
||||||
archiveArtifacts artifacts: 'build/reports/checkstyle/*.html', allowEmptyArchive: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Test') {
|
|
||||||
when {
|
|
||||||
expression { IS_MR }
|
|
||||||
}
|
|
||||||
steps {
|
|
||||||
sh './gradlew test'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Build') {
|
|
||||||
when {
|
|
||||||
expression { IS_MR }
|
|
||||||
}
|
|
||||||
steps {
|
|
||||||
sh './gradlew build -x test'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Build Docker Image') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
IMAGE_TAG = "${IS_MR ? IMAGE_NAME_MR : IMAGE_NAME_MAIN}:${COMMIT_HASH}"
|
|
||||||
sh "docker buildx build -t ${IMAGE_TAG} ."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Push Docker Image') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
sh "echo ${DOCKERHUB_CREDENTIALS_PSW} | docker login -u ${DOCKERHUB_CREDENTIALS_USR} --password-stdin"
|
|
||||||
sh "docker push ${IMAGE_TAG}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stage('Build (No Tests)') {
|
||||||
|
when {
|
||||||
|
not { branch 'main' }
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh './gradlew build -x test'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build Docker Image') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
def tag = BRANCH_NAME == 'main' ? 'latest' : "${COMMIT}"
|
||||||
|
def repo = BRANCH_NAME == 'main' ? "${DOCKER_IMAGE}-main" : "${DOCKER_IMAGE}-mr"
|
||||||
|
sh "docker build -t ${repo}:${tag} ."
|
||||||
|
withCredentials([usernamePassword(credentialsId: 'dockerhub', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
|
||||||
|
sh "echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin"
|
||||||
|
sh "docker push ${repo}:${tag}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue