-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
119 lines (105 loc) · 3.21 KB
/
Jenkinsfile
File metadata and controls
119 lines (105 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
pipeline {
agent any
environment {
SPRING_PROFILES_ACTIVE = 'dev'
SONAR_HOST_URL = 'http://localhost:9000'
SONAR_TOKEN = credentials('sonar-token')
DOCKERHUB_USERNAME = 'ibrahimdarghouthi1919'
DOCKERHUB_PASSWORD = credentials('dockerhub-password')
IMAGE_NAME = 'foyer-devops'
VERSION = 'latest'
}
stages {
stage('Checkout Code') {
steps {
git branch: 'main', url: 'https://github.com/Barhoum1919/foyer_devops.git'
}
}
stage('Build with Maven') {
steps {
sh 'mvn clean install'
}
}
stage('Run Tests') {
steps {
sh 'mvn test'
}
}
stage('Package') {
steps {
sh 'mvn package'
}
}
stage('SonarQube Analysis') {
steps {
sh """
mvn clean verify sonar:sonar \
-Dsonar.projectKey=foyer-devops \
-Dsonar.projectName='Foyer DevOps' \
-Dsonar.host.url=$SONAR_HOST_URL \
-Dsonar.login=$SONAR_TOKEN
"""
}
}
stage('Build Docker Image with Docker Compose') {
steps {
script {
// Build the Docker image for the 'app' service defined in docker-compose.yml
sh 'docker-compose build app'
}
}
}
stage('Login to Docker Hub') {
steps {
script {
// Login to Docker Hub using credentials
sh """
echo $DOCKERHUB_PASSWORD | docker login -u $DOCKERHUB_USERNAME --password-stdin
"""
}
}
}
stage('Tag Docker Image') {
steps {
script {
// Tag the built Docker image with the proper Docker Hub name and version
sh 'docker tag foyer-devops:latest $DOCKERHUB_USERNAME/$IMAGE_NAME:$VERSION'
}
}
}
stage('Push Docker Image to Docker Hub') {
steps {
script {
// Push the tagged Docker image to Docker Hub
sh 'docker push $DOCKERHUB_USERNAME/$IMAGE_NAME:$VERSION'
}
}
}
stage('Deploy to Nexus') {
steps {
sh 'mvn deploy'
}
}
stage('Deploy to Kubernetes (Minikube)') {
steps {
sshagent(credentials: ['ssh-wsl-credentials']) {
sh '''
ssh -o StrictHostKeyChecking=no ibrah@172.25.100.50 '
cd /mnt/c/Users/ibrah/Downloads/foyer/foyer &&
kubectl apply -f k8s/deployment.yaml &&
kubectl apply -f k8s/service.yaml
'
'''
}
}
}
}
post {
success {
echo 'Build, Docker push, and deployment succeeded!'
}
failure {
echo 'Build, Docker push, or deployment failed.'
}
}
}