-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
95 lines (82 loc) · 2.94 KB
/
Jenkinsfile
File metadata and controls
95 lines (82 loc) · 2.94 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
pipeline {
agent any
tools {
maven 'Maven'
}
environment {
SONARQUBE_SERVER = 'MySonarQubeServer'
SONAR_HOST_URL = 'http://10.0.0.143:9000'
}
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/raaidrushdy/UserManagementAPI'
}
}
stage('Build') {
steps {
echo 'Building the code...'
sh 'mvn clean package'
}
post {
success {
archiveArtifacts artifacts: '**/target/*.jar', allowEmptyArchive: true
}
}
}
stage('Test') {
steps {
echo 'Running unit tests...'
sh 'mvn test'
}
}
stage('Code Quality Analysis') {
steps {
echo 'Analyzing code with SonarQube...'
withSonarQubeEnv(SONARQUBE_SERVER) {
withCredentials([string(credentialsId: 'sonar-token', variable: 'SONAR_TOKEN')]) {
sh 'mvn sonar:sonar -Dsonar.login=$SONAR_TOKEN -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.projectKey=user-management-api-new -Dsonar.projectName="User Management API"'
}
}
}
}
stage('Deploy to Staging') {
steps {
echo 'Building Docker image...'
sh 'docker build -t user-management-api .'
echo 'Stopping and removing old container (if exists)...'
sh 'docker stop user-management-api-staging || true'
sh 'docker rm user-management-api-staging || true'
echo 'Running Docker container in staging...'
sh 'docker run -d -p 8081:8080 --name user-management-api-staging user-management-api'
}
}
stage('Deploy to Production') {
steps {
echo 'Building Docker image for production...'
sh 'docker build -f Dockerfile.prod -t user-management-api-prod .'
echo 'Running Docker container in production...'
sh 'docker stop user-management-api-prod || true'
sh 'docker rm user-management-api-prod || true'
sh 'docker run --rm -d -p 8080:8080 --name user-management-api-prod user-management-api-prod'
}
}
stage('Monitoring and Alerting with New Relic') {
steps {
echo 'Monitoring production environment with New Relic Infrastructure agent...'
// No need to start the agent again; it's already running
}
}
}
post {
always {
echo 'Pipeline finished with status: ' + currentBuild.currentResult
}
success {
echo 'Pipeline completed successfully!'
}
failure {
echo 'Pipeline failed!'
}
}
}