mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 14:55:50 +00:00
Merge pull request #3 from CChariot/FinalProject_main
Final project main
This commit is contained in:
commit
a3c15027d5
3 changed files with 32 additions and 26 deletions
|
@ -12,7 +12,7 @@ COPY mvnw pom.xml ./
|
|||
COPY src ./src
|
||||
|
||||
# Package the application
|
||||
RUN ./mvnw clean package
|
||||
RUN ./mvnw clean package -DskipTests
|
||||
|
||||
# Copy the JAR file to the app directory
|
||||
COPY target/*.jar app.jar
|
||||
|
|
50
Jenkinsfile
vendored
50
Jenkinsfile
vendored
|
@ -2,48 +2,50 @@ pipeline {
|
|||
agent any
|
||||
|
||||
environment {
|
||||
DOCKER_CREDENTIALS_ID = 'your-docker-credentials-id' // Replace with your actual Docker credentials ID
|
||||
SONARQUBE_URL = 'http://sonarqube:9000'
|
||||
SONARQUBE_CREDENTIALS_ID = 'admin'
|
||||
GITHUB_TOKEN = credentials('github-token')
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
checkout scm
|
||||
}
|
||||
}
|
||||
stage('Build') {
|
||||
steps {
|
||||
script {
|
||||
sh './mvnw clean package'
|
||||
echo "Checking out code..."
|
||||
git url: 'https://github.com/CChariot/spring-petclinic.git', branch: 'FinalProject_main', credentialsId: 'github-token'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build Docker Image') {
|
||||
steps {
|
||||
script {
|
||||
// Build the Docker image
|
||||
sh 'docker build -t petclinic:latest .'
|
||||
echo "Building Docker Image..."
|
||||
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('Push Docker Image') {
|
||||
steps {
|
||||
script {
|
||||
// Push the Docker image to a registry
|
||||
docker.withRegistry('https://index.docker.io/v1/', "${DOCKER_CREDENTIALS_ID}") {
|
||||
sh 'docker tag petclinic:latest your-docker-username/petclinic:latest'
|
||||
sh 'docker push your-docker-username/petclinic:latest'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
script {
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
script {
|
||||
// Deploy the application using Docker Compose
|
||||
sh 'docker-compose up -d'
|
||||
}
|
||||
}
|
||||
success {
|
||||
echo 'Pipeline completed successfully!'
|
||||
}
|
||||
failure {
|
||||
echo 'Pipeline failed.'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,10 @@ services:
|
|||
- prometheus
|
||||
|
||||
jenkins:
|
||||
image: jenkins/jenkins:lts
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.jenkins
|
||||
image: my-jenkins:latest
|
||||
ports:
|
||||
- "8081:8080"
|
||||
- "50000:50000"
|
||||
|
@ -48,6 +51,7 @@ services:
|
|||
volumes:
|
||||
- jenkins_data:/var/jenkins_home
|
||||
- ./jenkins.yaml:/var/jenkins_home/casc_configs/jenkins.yaml
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
networks:
|
||||
- custom-network
|
||||
|
||||
|
|
Loading…
Reference in a new issue