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
24a8d6b08f
commit
cc2a12ebf1
1 changed files with 27 additions and 12 deletions
35
Jenkinsfile
vendored
35
Jenkinsfile
vendored
|
@ -2,9 +2,9 @@ pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
MAVEN_HOME = tool 'M3' //
|
MAVEN_HOME = tool 'M3' // Assuming your Maven tool in Jenkins is named "M3"
|
||||||
DOCKER_REPO_MR = "iancumatei67/mr" //
|
DOCKER_REPO_MR = "iancumatei67/mr" // Change to your Docker registry/repository for merge requests
|
||||||
DOCKER_REPO_MAIN = "iancumatei67/main" //
|
DOCKER_REPO_MAIN = "iancumatei67/main" // Change to your Docker registry/repository for main branch
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
|
@ -44,7 +44,7 @@ pipeline {
|
||||||
script {
|
script {
|
||||||
app = docker.build("iancumatei67/main")
|
app = docker.build("iancumatei67/main")
|
||||||
app.inside {
|
app.inside {
|
||||||
sh 'echo $(curl https://7bf7-85-204-75-2.ngrok-free.app)'
|
sh 'echo $(curl localhost:8080)'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build and Push Docker Image (MR)') {
|
stage('Build Docker Image (MR)') {
|
||||||
when {
|
when {
|
||||||
expression {
|
expression {
|
||||||
// Execute this stage only for merge requests
|
// Execute this stage only for merge requests
|
||||||
|
@ -73,13 +73,28 @@ pipeline {
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
// Build Docker image
|
def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
||||||
def dockerImage = docker.build("${DOCKER_REPO_MR}:${env.CHANGE_ID}", '.')
|
appMR = docker.build("${DOCKER_REPO_MR}:${gitCommitShort}")
|
||||||
|
appMR.inside {
|
||||||
|
sh 'echo $(curl localhost:8080)'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Push Docker image
|
stage('Push Docker Image (MR)') {
|
||||||
|
when {
|
||||||
|
expression {
|
||||||
|
// Execute this stage only for merge requests
|
||||||
|
return env.CHANGE_ID != null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
||||||
docker.withRegistry('https://registry.hub.docker.com', 'docker_hub_login') {
|
docker.withRegistry('https://registry.hub.docker.com', 'docker_hub_login') {
|
||||||
dockerImage.push("${env.CHANGE_ID}")
|
appMR.push("${DOCKER_REPO_MR}:${gitCommitShort}")
|
||||||
dockerImage.push("latest")
|
appMR.push("latest")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue