mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 07:45:49 +00:00
Trying to make the pipeline work
This commit is contained in:
parent
0c2ca23169
commit
4f060c8ece
2 changed files with 85 additions and 1 deletions
|
@ -4,6 +4,6 @@ WORKDIR /app
|
||||||
|
|
||||||
COPY target/spring-petclinic-*.jar /app/spring-petclinic.jar
|
COPY target/spring-petclinic-*.jar /app/spring-petclinic.jar
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8081
|
||||||
|
|
||||||
CMD ["java", "-jar", "spring-petclinic.jar"]
|
CMD ["java", "-jar", "spring-petclinic.jar"]
|
||||||
|
|
84
Jenkinsfile
vendored
Normal file
84
Jenkinsfile
vendored
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
|
||||||
|
environment {
|
||||||
|
MAVEN_HOME = tool 'M3' // Assuming your Maven tool in Jenkins is named "M3"
|
||||||
|
DOCKER_REPO_MR = "iancumatei67/mr" // Change to your Docker registry/repository for merge requests
|
||||||
|
DOCKER_REPO_MAIN = "iancumatei67/main" // Change to your Docker registry/repository for main branch
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('Checkstyle') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
// Use Maven for Checkstyle
|
||||||
|
sh "${MAVEN_HOME}/bin/mvn checkstyle:checkstyle"
|
||||||
|
archiveArtifacts 'target/checkstyle-result.xml'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Test') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
// Use Maven for testing
|
||||||
|
sh "${MAVEN_HOME}/bin/mvn test"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
// Use Maven for building without tests
|
||||||
|
sh "${MAVEN_HOME}/bin/mvn package -DskipTests"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Create Docker Image (MR)') {
|
||||||
|
when {
|
||||||
|
expression {
|
||||||
|
// Execute this stage only for merge requests
|
||||||
|
return env.CHANGE_ID != null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
// Assuming Dockerfile is at the root of the spring-petclinic repo
|
||||||
|
def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
||||||
|
def dockerImageTag = "${DOCKER_REPO_MR}:${gitCommitShort}"
|
||||||
|
|
||||||
|
sh "docker build -t ${dockerImageTag} ."
|
||||||
|
sh "docker push ${dockerImageTag}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Create Docker Image (Main)') {
|
||||||
|
when {
|
||||||
|
expression {
|
||||||
|
// Execute this stage only for the main branch
|
||||||
|
return env.BRANCH_NAME == 'main'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
// Assuming Dockerfile is at the root of the spring-petclinic repo
|
||||||
|
def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
||||||
|
def dockerImageTag = "${DOCKER_REPO_MAIN}:${gitCommitShort}"
|
||||||
|
|
||||||
|
sh "docker build -t ${dockerImageTag} ."
|
||||||
|
sh "docker push ${dockerImageTag}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
cleanWs() // Clean workspace after the pipeline execution
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue