mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:35:50 +00:00
Update Jenkinsfile
Signed-off-by: prankumargrid <prankumar@griddynamics.com>
This commit is contained in:
parent
00e590de05
commit
0831c86fbc
1 changed files with 52 additions and 23 deletions
75
Jenkinsfile
vendored
75
Jenkinsfile
vendored
|
@ -2,19 +2,31 @@ pipeline {
|
|||
agent any
|
||||
|
||||
environment {
|
||||
IMAGE_TAG = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
||||
REGISTRY = "your-dockerhub-username" // Or Nexus repo URL
|
||||
IMAGE_TAG = '' // We'll set this inside steps
|
||||
REGISTRY = "your-dockerhub-username" // Replace with your actual DockerHub username or Nexus repo
|
||||
}
|
||||
|
||||
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') {
|
||||
script {
|
||||
if (env.BRANCH_NAME == 'main') {
|
||||
currentBuild.description = "Main branch build"
|
||||
buildMainPipeline()
|
||||
} else {
|
||||
currentBuild.description = "Merge request build"
|
||||
buildMRPipeline()
|
||||
steps {
|
||||
script {
|
||||
if (env.BRANCH_NAME == 'main') {
|
||||
currentBuild.description = "Main branch build"
|
||||
buildMainPipeline()
|
||||
} else {
|
||||
currentBuild.description = "Merge request build"
|
||||
buildMRPipeline()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,11 +34,13 @@ pipeline {
|
|||
}
|
||||
|
||||
def buildMainPipeline() {
|
||||
stage('Docker Build and Push') {
|
||||
script {
|
||||
docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-credentials-id') {
|
||||
def app = docker.build("${env.REGISTRY}/main:${env.IMAGE_TAG}")
|
||||
app.push()
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,26 +48,41 @@ def buildMainPipeline() {
|
|||
|
||||
def buildMRPipeline() {
|
||||
stage('Checkstyle') {
|
||||
sh 'gradle checkstyleMain checkstyleTest'
|
||||
archiveArtifacts artifacts: '**/build/reports/checkstyle/*.xml', allowEmptyArchive: true
|
||||
steps {
|
||||
script {
|
||||
sh 'gradle checkstyleMain checkstyleTest'
|
||||
archiveArtifacts artifacts: '**/build/reports/checkstyle/*.xml', allowEmptyArchive: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Test') {
|
||||
sh 'gradle test'
|
||||
steps {
|
||||
script {
|
||||
sh 'gradle test'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build (No Tests)') {
|
||||
sh 'gradle build -x test'
|
||||
steps {
|
||||
script {
|
||||
sh 'gradle build -x test'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Docker Build and Push') {
|
||||
script {
|
||||
docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-credentials-id') {
|
||||
def app = docker.build("${env.REGISTRY}/mr:${env.IMAGE_TAG}")
|
||||
app.push()
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue