Update Jenkinsfile

Signed-off-by: prankumargrid <prankumar@griddynamics.com>
This commit is contained in:
prankumargrid 2025-04-29 12:47:20 +05:30 committed by GitHub
parent 00e590de05
commit 0831c86fbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

37
Jenkinsfile vendored
View file

@ -2,12 +2,23 @@ pipeline {
agent any agent any
environment { environment {
IMAGE_TAG = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim() IMAGE_TAG = '' // We'll set this inside steps
REGISTRY = "your-dockerhub-username" // Or Nexus repo URL REGISTRY = "your-dockerhub-username" // Replace with your actual DockerHub username or Nexus repo
} }
stages { stages {
stage('Initialize') {
steps {
script {
IMAGE_TAG = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
env.IMAGE_TAG = IMAGE_TAG // Save it to env for next stages
echo "Image tag is: ${env.IMAGE_TAG}"
}
}
}
stage('Check Branch') { stage('Check Branch') {
steps {
script { script {
if (env.BRANCH_NAME == 'main') { if (env.BRANCH_NAME == 'main') {
currentBuild.description = "Main branch build" currentBuild.description = "Main branch build"
@ -19,10 +30,12 @@ pipeline {
} }
} }
} }
}
} }
def buildMainPipeline() { def buildMainPipeline() {
stage('Docker Build and Push') { stage('Docker Build and Push for Main') {
steps {
script { script {
docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-credentials-id') { docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-credentials-id') {
def app = docker.build("${env.REGISTRY}/main:${env.IMAGE_TAG}") def app = docker.build("${env.REGISTRY}/main:${env.IMAGE_TAG}")
@ -30,23 +43,37 @@ def buildMainPipeline() {
} }
} }
} }
}
} }
def buildMRPipeline() { def buildMRPipeline() {
stage('Checkstyle') { stage('Checkstyle') {
steps {
script {
sh 'gradle checkstyleMain checkstyleTest' sh 'gradle checkstyleMain checkstyleTest'
archiveArtifacts artifacts: '**/build/reports/checkstyle/*.xml', allowEmptyArchive: true archiveArtifacts artifacts: '**/build/reports/checkstyle/*.xml', allowEmptyArchive: true
} }
}
}
stage('Test') { stage('Test') {
steps {
script {
sh 'gradle test' sh 'gradle test'
} }
}
}
stage('Build (No Tests)') { stage('Build (No Tests)') {
steps {
script {
sh 'gradle build -x test' sh 'gradle build -x test'
} }
}
}
stage('Docker Build and Push') { stage('Docker Build and Push for MR') {
steps {
script { script {
docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-credentials-id') { docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-credentials-id') {
def app = docker.build("${env.REGISTRY}/mr:${env.IMAGE_TAG}") def app = docker.build("${env.REGISTRY}/mr:${env.IMAGE_TAG}")
@ -54,6 +81,8 @@ def buildMRPipeline() {
} }
} }
} }
}
} }