mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-25 00:25:50 +00:00
Update Jenkinsfile
This commit is contained in:
parent
aab630d6a3
commit
522d1c380e
1 changed files with 16 additions and 11 deletions
17
Jenkinsfile
vendored
17
Jenkinsfile
vendored
|
@ -1,3 +1,5 @@
|
|||
#!/usr/bin/env groovy
|
||||
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
|
@ -10,13 +12,10 @@ pipeline {
|
|||
stage('Prepare') {
|
||||
steps {
|
||||
script {
|
||||
// Grab branch name
|
||||
env.GIT_BRANCH_NAME = sh(script: "git rev-parse --abbrev-ref HEAD", returnStdout: true).trim()
|
||||
// Grab short commit
|
||||
// Use Jenkins environment variable or fallback to git command
|
||||
env.GIT_BRANCH_NAME = env.BRANCH_NAME ?: sh(script: "git rev-parse --abbrev-ref HEAD", returnStdout: true).trim()
|
||||
env.GIT_COMMIT_SHORT = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
||||
|
||||
// Add this line for branch name confirmation
|
||||
echo "Detected Branch: ${env.GIT_BRANCH_NAME}"
|
||||
echo "Branch: ${env.GIT_BRANCH_NAME}"
|
||||
echo "Commit: ${env.GIT_COMMIT_SHORT}"
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +28,7 @@ pipeline {
|
|||
steps {
|
||||
echo 'Running Checkstyle...'
|
||||
sh "./gradlew checkstyleMain checkstyleTest"
|
||||
// Archive checkstyle reports as artifacts
|
||||
archiveArtifacts artifacts: 'build/reports/checkstyle/*.xml', fingerprint: true
|
||||
}
|
||||
}
|
||||
|
@ -56,10 +56,13 @@ pipeline {
|
|||
stage('Docker Build & Push') {
|
||||
steps {
|
||||
script {
|
||||
// Decide which repo to push to based on the branch
|
||||
if (env.GIT_BRANCH_NAME == 'main') {
|
||||
// Main branch
|
||||
echo "Building Docker image for main-jenkins repo..."
|
||||
sh "docker build -t ${DOCKERHUB_USERNAME}/main-jenkins:${GIT_COMMIT_SHORT} ."
|
||||
|
||||
// Login & push
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: "${DOCKERHUB_CREDENTIALS}",
|
||||
usernameVariable: 'DOCKER_USER',
|
||||
|
@ -71,7 +74,9 @@ pipeline {
|
|||
sh "docker push ${DOCKERHUB_USERNAME}/main-jenkins:${GIT_COMMIT_SHORT}"
|
||||
sh "docker tag ${DOCKERHUB_USERNAME}/main-jenkins:${GIT_COMMIT_SHORT} ${DOCKERHUB_USERNAME}/main-jenkins:latest"
|
||||
sh "docker push ${DOCKERHUB_USERNAME}/main-jenkins:latest"
|
||||
|
||||
} else {
|
||||
// Feature or merge-request branch
|
||||
echo "Building Docker image for mr-jenkins repo..."
|
||||
sh "docker build -t ${DOCKERHUB_USERNAME}/mr-jenkins:${GIT_COMMIT_SHORT} ."
|
||||
|
||||
|
|
Loading…
Reference in a new issue