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
0e7ad0984e
commit
8d18fa01dd
1 changed files with 65 additions and 65 deletions
86
Jenkinsfile
vendored
86
Jenkinsfile
vendored
|
@ -1,71 +1,71 @@
|
||||||
pipeline {
|
pipeline {
|
||||||
agent {
|
agent any
|
||||||
docker {
|
|
||||||
image 'docker:24.0.5-dind' // Or use another version
|
|
||||||
args '--privileged' // Required to run Docker inside Docker
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
imageTag = "latest"
|
IMAGE_TAG = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
||||||
REGISTRY_URL = "https://hub.docker.com/repositories/prankumar313"
|
REGISTRY = "your-dockerhub-username" // Or Nexus repo URL
|
||||||
IMAGE_NAME = "spring-petclinic"
|
|
||||||
GIT_COMMIT_SHORT = "${env.GIT_COMMIT[0..6]}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Checkstyle'){
|
stage('Check Branch') {
|
||||||
when{
|
|
||||||
not{
|
|
||||||
branch 'main'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
sh './gradlew checkstyleMain'
|
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') {
|
||||||
|
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 {
|
||||||
|
sh 'gradle checkstyleMain checkstyleTest'
|
||||||
archiveArtifacts artifacts: '**/build/reports/checkstyle/*.xml', allowEmptyArchive: true
|
archiveArtifacts artifacts: '**/build/reports/checkstyle/*.xml', allowEmptyArchive: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Test') {
|
stage('Test') {
|
||||||
when{
|
|
||||||
not{
|
|
||||||
branch 'main'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
sh './gradlew test'
|
sh 'gradle test'
|
||||||
junit '**/build/test-results/test/*.xml'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build'){
|
stage('Build (No Tests)') {
|
||||||
steps {
|
steps {
|
||||||
sh './gradlew clean build -x test'
|
sh 'gradle build -x test'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build Docker Image'){
|
stage('Docker Build and Push') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
def ImageTag = env.BRANCH_NAME == 'main' ? 'latest' : GIT_COMMIT_SHORT
|
docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-credentials-id') {
|
||||||
sh "docker build -t www.github.com/prankumargrid/$IMAGE_NAME:$imageTag ."
|
def app = docker.build("${env.REGISTRY}/mr:${env.IMAGE_TAG}")
|
||||||
}
|
app.push()
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Push Docker Image'){
|
|
||||||
steps{
|
|
||||||
script{
|
|
||||||
def targetRepo = env.BRANCH_NAME == 'main' ? 'main' : 'mr'
|
|
||||||
def imageTag = env.BRANCH_NAME == 'main' ? 'latest' : GIT_COMMIT_SHORT
|
|
||||||
sh """
|
|
||||||
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin $REGISTRY_URL
|
|
||||||
docker tag $REGISTRY_URL/$IMAGE_NAME:$imageTag $REGISTRY_URL/$targetRepo/$IMAGE_NAME:$imageTag
|
|
||||||
docker push $REGISTRY_URL/$targetRepo/$IMAGE_NAME:$imageTag
|
|
||||||
"""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue