mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 23:05:49 +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')
|
GITHUB_TOKEN = credentials('github-token')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define dockerImage at a higher scope to ensure availability in post block
|
|
||||||
def dockerImage = null
|
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout') {
|
stage('Checkout') {
|
||||||
steps {
|
steps {
|
||||||
|
@ -24,41 +21,25 @@ pipeline {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "Building Docker Image..."
|
echo "Building Docker Image..."
|
||||||
dockerImage = docker.build("spring-petclinic")
|
def dockerImage = docker.build("spring-petclinic")
|
||||||
echo "Docker Image built: ${dockerImage.id}"
|
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') {
|
// Further stages would reference env.DOCKER_IMAGE_ID if needed
|
||||||
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
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
script {
|
script {
|
||||||
try {
|
// Use the saved Docker image ID from the environment if needed
|
||||||
if (dockerImage != null) {
|
if (env.DOCKER_IMAGE_ID) {
|
||||||
echo "Stopping and removing Docker Image..."
|
echo "Stopping and removing Docker Image with ID: ${env.DOCKER_IMAGE_ID}"
|
||||||
dockerImage.stop()
|
docker.rmi(env.DOCKER_IMAGE_ID)
|
||||||
dockerImage.remove()
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
echo "Error during cleanup: ${e.message}"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue