mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 07:45:49 +00:00
Update Jenkinsfile
This commit is contained in:
parent
4f060c8ece
commit
c726cd4f3f
1 changed files with 12 additions and 24 deletions
36
Jenkinsfile
vendored
36
Jenkinsfile
vendored
|
@ -36,44 +36,32 @@ pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Create Docker Image (MR)') {
|
stage('Build Docker Image') {
|
||||||
when {
|
when {
|
||||||
expression {
|
branch 'main'
|
||||||
// Execute this stage only for merge requests
|
|
||||||
return env.CHANGE_ID != null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
// Assuming Dockerfile is at the root of the spring-petclinic repo
|
app = docker.build("iancumatei67/main")
|
||||||
def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
app.inside {
|
||||||
def dockerImageTag = "${DOCKER_REPO_MR}:${gitCommitShort}"
|
sh 'echo $(curl localhost:8080)'
|
||||||
|
}
|
||||||
sh "docker build -t ${dockerImageTag} ."
|
|
||||||
sh "docker push ${dockerImageTag}"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stage('Push Docker Image') {
|
||||||
stage('Create Docker Image (Main)') {
|
|
||||||
when {
|
when {
|
||||||
expression {
|
branch 'main'
|
||||||
// Execute this stage only for the main branch
|
|
||||||
return env.BRANCH_NAME == 'main'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
// Assuming Dockerfile is at the root of the spring-petclinic repo
|
docker.withRegistry('https://registry.hub.docker.com', 'docker_hub_login') {
|
||||||
def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
app.push("${env.BUILD_NUMBER}")
|
||||||
def dockerImageTag = "${DOCKER_REPO_MAIN}:${gitCommitShort}"
|
app.push("latest")
|
||||||
|
}
|
||||||
sh "docker build -t ${dockerImageTag} ."
|
|
||||||
sh "docker push ${dockerImageTag}"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
|
|
Loading…
Reference in a new issue