mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 14:55:50 +00:00
Latest Jenkinsfile
This commit is contained in:
parent
9ebda3d048
commit
fb152b9c32
1 changed files with 8 additions and 27 deletions
35
Jenkinsfile
vendored
35
Jenkinsfile
vendored
|
@ -7,9 +7,6 @@ pipeline {
|
|||
GITHUB_TOKEN = credentials('github-token')
|
||||
}
|
||||
|
||||
// Define dockerImage at a higher scope to ensure availability in post block
|
||||
def dockerImage = null
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
|
@ -24,41 +21,25 @@ pipeline {
|
|||
steps {
|
||||
script {
|
||||
echo "Building Docker Image..."
|
||||
dockerImage = docker.build("spring-petclinic")
|
||||
def dockerImage = docker.build("spring-petclinic")
|
||||
echo "Docker Image built: ${dockerImage.id}"
|
||||
// Store the Docker image ID in the environment if needed across stages
|
||||
env.DOCKER_IMAGE_ID = dockerImage.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('SonarQube Analysis') {
|
||||
steps {
|
||||
script {
|
||||
echo "Starting SonarQube analysis..."
|
||||
withSonarQubeEnv('SonarQube') {
|
||||
dockerImage.inside("-u root") {
|
||||
sh './mvnw sonar:sonar -Dsonar.projectKey=spring-petclinic'
|
||||
}
|
||||
}
|
||||
echo "SonarQube analysis completed."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Other stages omitted for brevity
|
||||
// Further stages would reference env.DOCKER_IMAGE_ID if needed
|
||||
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
script {
|
||||
try {
|
||||
if (dockerImage != null) {
|
||||
echo "Stopping and removing Docker Image..."
|
||||
dockerImage.stop()
|
||||
dockerImage.remove()
|
||||
}
|
||||
} catch (Exception e) {
|
||||
echo "Error during cleanup: ${e.message}"
|
||||
// Use the saved Docker image ID from the environment if needed
|
||||
if (env.DOCKER_IMAGE_ID) {
|
||||
echo "Stopping and removing Docker Image with ID: ${env.DOCKER_IMAGE_ID}"
|
||||
docker.rmi(env.DOCKER_IMAGE_ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue