mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 13:05:49 +00:00
feat: add Jenkinsfile and modify Dockerfile.two
This commit is contained in:
parent
5ccc487ba9
commit
79eb4625f1
2 changed files with 88 additions and 5 deletions
|
@ -4,9 +4,9 @@ WORKDIR /app
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN ["mvn", "clean", "install"]
|
RUN ["mvn", "clean", "install", "-DskipTests"]
|
||||||
|
|
||||||
FROM eclipse-temurin
|
FROM gcr.io/distroless/java21-debian12
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
@ -14,6 +14,4 @@ COPY --from=builder /app/target/spring-petclinic-*.jar app.jar
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
ENTRYPOINT ["java","-jar","app.jar"]
|
ENTRYPOINT ["java","-jar","app.jar"]
|
||||||
|
|
||||||
|
|
85
Jenkinsfile
vendored
Normal file
85
Jenkinsfile
vendored
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
|
||||||
|
environment {
|
||||||
|
GIT_COMMIT_SHORT = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('Checkout') {
|
||||||
|
steps {
|
||||||
|
checkout scm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Merge Request (MR) jobs only ===
|
||||||
|
stage('Checkstyle') {
|
||||||
|
when {
|
||||||
|
expression { return env.CHANGE_ID != null }
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh 'mvn checkstyle:checkstyle'
|
||||||
|
}
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
archiveArtifacts artifacts: 'target/checkstyle-result.xml', fingerprint: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Test') {
|
||||||
|
when {
|
||||||
|
expression { return env.CHANGE_ID != null }
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh 'mvn test'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build (no tests)') {
|
||||||
|
when {
|
||||||
|
expression { return env.CHANGE_ID != null }
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh 'mvn package -DskipTests'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Docker build and push for both MR and main ===
|
||||||
|
stage('Build & Push Docker Image') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
def isMR = env.CHANGE_ID != null
|
||||||
|
|
||||||
|
// Define repo and tag based on context
|
||||||
|
def repo = isMR ? "ggonzalezx/mr" : "ggonzalezx/main"
|
||||||
|
|
||||||
|
def tag = isMR ? "${GIT_COMMIT_SHORT}" : "latest"
|
||||||
|
|
||||||
|
def fullImageName = "${repo}:${tag}"
|
||||||
|
|
||||||
|
echo "Building Docker image with Dockerfile.two: ${fullImageName}"
|
||||||
|
|
||||||
|
// Build using Dockerfile.two
|
||||||
|
docker.build(fullImageName, "-f Dockerfile.two .")
|
||||||
|
|
||||||
|
// Authenticate and push to Docker Hub
|
||||||
|
docker.withRegistry('https://index.docker.io/v1/', 'dockerhub-credentials') {
|
||||||
|
docker.image(fullImageName).push()
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Docker image pushed to: https://hub.docker.com/repository/docker/${repo}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
success {
|
||||||
|
echo "Pipeline SUCCESS for ${env.BRANCH_NAME} (${env.CHANGE_ID ?: 'not an MR'})"
|
||||||
|
}
|
||||||
|
failure {
|
||||||
|
echo "Pipeline FAILURE for ${env.BRANCH_NAME} (${env.CHANGE_ID ?: 'not an MR'})"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue