From d85042cdf5a098286edbe0cde29de32bf04f75bc Mon Sep 17 00:00:00 2001 From: prankumargrid Date: Tue, 29 Apr 2025 12:57:48 +0530 Subject: [PATCH] Update Jenkinsfile Signed-off-by: prankumargrid --- Jenkinsfile | 74 ++++++----------------------------------------------- 1 file changed, 8 insertions(+), 66 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c4fb25f37..08b0f3419 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,87 +2,29 @@ pipeline { agent any environment { - IMAGE_TAG = '' // We'll set this inside steps - REGISTRY = "your-dockerhub-username" // Replace with your actual DockerHub username or Nexus repo + IMAGE_TAG = '' // Will be set in 'Initialize' + REGISTRY = "your-dockerhub-username" // Replace with actual DockerHub or Nexus repo } stages { stage('Initialize') { steps { script { - def IMAGE_TAG = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim() - env.IMAGE_TAG = IMAGE_TAG // Save it to env for next stages + env.IMAGE_TAG = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim() echo "Image tag is: ${env.IMAGE_TAG}" } } } - stage('Check Branch') { + stage('Branch Specific Pipeline') { steps { script { if (env.BRANCH_NAME == 'main') { currentBuild.description = "Main branch build" - buildMainPipeline() - } else { - currentBuild.description = "Merge request build" - buildMRPipeline() - } - } - } - } - } -} - -def buildMainPipeline() { - stage('Docker Build and Push for Main') { - steps { - script { - docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-credentials-id') { - def app = docker.build("${env.REGISTRY}/main:${env.IMAGE_TAG}") - app.push() - } - } - } - } -} - -def buildMRPipeline() { - stage('Checkstyle') { - steps { - script { - sh 'gradle checkstyleMain checkstyleTest' - archiveArtifacts artifacts: '**/build/reports/checkstyle/*.xml', allowEmptyArchive: true - } - } - } - - stage('Test') { - steps { - script { - sh 'gradle test' - } - } - } - - stage('Build (No Tests)') { - steps { - script { - sh 'gradle build -x test' - } - } - } - - stage('Docker Build and Push for MR') { - steps { - script { - docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-credentials-id') { - def app = docker.build("${env.REGISTRY}/mr:${env.IMAGE_TAG}") - app.push() - } - } - } - } -} + + // Main branch: Just build and push image + docker.withRegistry(' +