forked from webpwnized/mutillidae
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
82 lines (75 loc) · 2.69 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
pipeline {
agent any
tools {
// Define tools if needed (optional for PHP)
}
environment {
SONAR_TOKEN = credentials('SONAR_TOKEN') // SonarQube token from Jenkins credentials
MYSQL_ROOT_PASSWORD = 'root' // MySQL root password for the MySQL container
}
stages {
stage('Start MySQL Service') {
steps {
script {
// Start MySQL as a service container
sh '''
docker run --name mysql-server -e MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} -d mysql:5.7
'''
}
}
}
stage('SonarQube Analysis') {
steps {
withCredentials([string(credentialsId: 'SONAR_TOKEN', variable: 'SONAR_TOKEN')]) {
script {
// Run SonarScanner for PHP with the correct SonarQube server URL and project key
sh '''
sonar-scanner \
-Dsonar.projectKey=Mutillidae-II \
-Dsonar.sources=. \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=$SONAR_TOKEN \
-Dsonar.php.tests.reportPath=./test-reports/unit-report.xml \
-Dsonar.php.coverage.reportPaths=./test-reports/coverage.xml
'''
}
}
}
}
stage('Build PHP Application Docker Image') {
steps {
withDockerRegistry([credentialsId: "dockerlogin", url: ""]) {
script {
// Build the PHP application Docker image
app = docker.build("angel3/mutillidae:latest")
}
}
}
}
}
stage('Quality Gate') {
steps {
script {
// Wait for the quality gate result from SonarQube
timeout(time: 10, unit: 'MINUTES') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline failed due to SonarQube quality gate failure: ${qg.status}"
}
}
}
}
}
post {
always {
stage('Tear Down') {
steps {
script {
// Stop MySQL container after use
sh 'docker stop mysql-server && docker rm mysql-server'
}
}
}
}
}
}