mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 23:35:50 +00:00
Update Jenkinsfile
This commit is contained in:
parent
266ef56ae5
commit
079784383d
1 changed files with 67 additions and 29 deletions
98
Jenkinsfile
vendored
98
Jenkinsfile
vendored
|
@ -1,68 +1,106 @@
|
||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
|
environment {
|
||||||
|
MAVEN_HOME = tool 'M3'
|
||||||
|
DOCKER_REPO_MR = "mihailinternul/mr"
|
||||||
|
DOCKER_REPO_MAIN = "mihailinternul/main"
|
||||||
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Checkstyle') {
|
stage('Checkstyle') {
|
||||||
when {
|
|
||||||
expression { env.CHANGE_TARGET ==~ /^merge$/ }
|
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
// Use Maven checkstyle plugin to generate a code style report
|
|
||||||
script {
|
script {
|
||||||
sh 'M3/bin/mvn checkstyle:checkstyle'
|
// Use Maven for Checkstyle
|
||||||
}
|
sh "${MAVEN_HOME}/bin/mvn checkstyle:checkstyle"
|
||||||
archiveArtifacts artifacts: '**/target/checkstyle-result.xml', fingerprint: true
|
archiveArtifacts 'target/checkstyle-result.xml'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('Test') {
|
stage('Test') {
|
||||||
when {
|
|
||||||
expression { env.CHANGE_TARGET ==~ /^merge$/ }
|
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
// Run tests with Maven
|
|
||||||
script {
|
script {
|
||||||
sh 'M3/bin/mvn test'
|
// Use Maven for testing
|
||||||
|
sh "${MAVEN_HOME}/bin/mvn test"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
when {
|
|
||||||
expression { env.CHANGE_TARGET ==~ /^merge$/ }
|
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
// Build without tests with Maven
|
|
||||||
script {
|
script {
|
||||||
sh 'M3/bin/mvn clean package -DskipTests'
|
// Use Maven for building without tests
|
||||||
|
sh "${MAVEN_HOME}/bin/mvn package -DskipTests"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Create Docker Image MR') {
|
|
||||||
|
stage('Build Docker Image (Main)') {
|
||||||
when {
|
when {
|
||||||
expression { env.CHANGE_TARGET ==~ /^merge$/ }
|
branch 'main'
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
app = docker.build("${DOCKER_REPO_MAIN}")
|
||||||
|
app.inside {
|
||||||
|
sh 'echo $(curl localhost:8080)'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Push Docker Image (Main)') {
|
||||||
|
when {
|
||||||
|
branch 'main'
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
docker.withRegistry('https://registry.hub.docker.com', 'docker_hub_login') {
|
||||||
|
app.push("${env.BUILD_NUMBER}")
|
||||||
|
app.push("latest")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build Docker Image (MR)') {
|
||||||
|
when {
|
||||||
|
expression {
|
||||||
|
return env.BRANCH_NAME == 'mr'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
// Build Docker image from Dockerfile
|
|
||||||
script {
|
script {
|
||||||
def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
||||||
def dockerImage = "mihailinternul/mr:${gitCommitShort}"
|
appMR = docker.build("${DOCKER_REPO_MR}:${gitCommitShort}")
|
||||||
sh "docker build -t ${dockerImage} ."
|
appMR.inside {
|
||||||
sh "docker push ${dockerImage}"
|
sh 'echo $(curl localhost:8080)'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Create Docker Image Main') {
|
}
|
||||||
|
|
||||||
|
stage('Push Docker Image (MR)') {
|
||||||
when {
|
when {
|
||||||
expression { env.CHANGE_TARGET ==~ /^main$/ }
|
expression {
|
||||||
|
return env.BRANCH_NAME == 'mr'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
// Build Docker image from Dockerfile
|
|
||||||
script {
|
script {
|
||||||
def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
docker.withRegistry('https://registry.hub.docker.com', 'docker_hub_login') {
|
||||||
def dockerImage = "mihailinternul/main:${gitCommitShort}"
|
appMR.push("${env.BUILD_NUMBER}")
|
||||||
sh "docker build -t ${dockerImage} ."
|
appMR.push("latest")
|
||||||
sh "docker push ${dockerImage}"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
cleanWs() // Clean workspace after the pipeline execution
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue