-
Notifications
You must be signed in to change notification settings - Fork 19
/
Jenkinsfile
93 lines (82 loc) · 3.29 KB
/
Jenkinsfile
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
pipeline {
agent any
stages {
// stage('Build & Test') {
// steps {
// script {
// // Build Docker images
// sh 'docker compose -p test -f docker-compose-test.yml --env-file prod.env up -d --build'
// def maxRetries = 10
// def retryCount = 0
// def commandSucceeded = false
// while (retryCount < maxRetries && !commandSucceeded) {
// try {
// // Replace the following line with your command
// sh 'docker exec test-tv-backend php artisan migrate --force'
// commandSucceeded = true
// } catch (Exception e) {
// retryCount++
// echo "Command failed. Retry count: ${retryCount}"
// if (retryCount >= maxRetries) {
// error "Command failed after ${maxRetries} attempts"
// }
// sleep 10 // Optional: wait before retrying
// }
// }
// // Run tests in the test-tv-backend container
// sh 'docker exec test-tv-backend php artisan test'
// }
// }
// }
// // Stage 2: SonarQube code analysis
// stage ("SonarQube Analysis ") {
// steps {
// script {
// def scannerHome = tool "sonar - scanner "
// withSonarQubeEnv ("SonarQube ") {
// sh "${ scannerHome }/bin/sonar - scanner " +
// "-Dsonar.projectKey = GitlabMx " +
// "-Dsonar.host.url = http://localhost:9000 " +
// "-Dsonar.login = sqp_5c7cf314cd19d3f60ed624ea584d547820ccd482 " +
// "-Dsonar.sources = ./app " +
// "-Dsonar.exclusions = 'vendor/* , storage/** , bootstrap/cache/*'"
// }
// }
// }
// }
// // Stage 3: Quality Gate check , pipeline will stop if the gate fails
// stage ("Quality Gate ") {
// steps {
// timeout ( time : 5 , unit : "MINUTES ") {
// waitForQualityGate abortPipeline : true
// }
// }
// }
stage('SonarQube Analysis') {
def scannerHome = tool 'SonarScanner';
withSonarQubeEnv() {
sh "${scannerHome}/bin/sonar-scanner"
}
}
stage('Build Docker Images') {
steps {
script {
// Build Docker images
sh 'docker compose -p prod --env-file prod.env up -d --force-recreate --build'
}
}
}
}
post {
always {
// stop testing containers
sh 'docker compose -p test -f docker-compose-test.yml down'
}
success {
echo 'Build, tests, and deployment were successful.'
}
failure {
echo 'Build or tests failed.'
}
}
}