forked from BretFisher/node-docker-good-defaults
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
142 lines (142 loc) · 6.13 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
pipeline {
agent none
environment {
DOCKERHUB_CREDENTIALS = credentials('DockerLogin')
//SNYK_CREDENTIALS = credentials('SnykToken')
}
stages {
//stage('Secret Scanning Using Trufflehog') {
// agent {
// docker {
// image 'trufflesecurity/trufflehog:latest'
// args '-u root --entrypoint='
// }
// }
// steps {
// catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
// sh 'trufflehog filesystem . --exclude-paths trufflehog-excluded-paths.txt --fail --json > trufflehog-scan-result.json'
// }
// sh 'cat trufflehog-scan-result.json'
// archiveArtifacts artifacts: 'trufflehog-scan-result.json'
// }
// }
stage('Build') {
agent {
docker {
image 'node:lts-buster-slim'
}
}
steps {
sh 'npm install'
}
}
stage('Test') {
agent {
docker {
image 'node:lts-buster-slim'
}
}
steps {
sh 'npm run test'
}
}
stage('SCA Trivy Scan Dockerfile Misconfiguration') {
agent {
docker {
image 'aquasec/trivy:latest'
args '-u root --network host --entrypoint='
}
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh 'trivy config Dockerfile --exit-code=1 > trivy-scan-dockerfile-report.txt'
}
sh 'cat trivy-scan-dockerfile-report.txt'
archiveArtifacts artifacts: 'trivy-scan-dockerfile-report.txt'
}
}
stage('SAST SonarQube') {
agent {
docker {
image 'sonarsource/sonar-scanner-cli:latest'
args '--network host -v ".:/usr/src" --entrypoint='
}
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh 'sonar-scanner -Dsonar.projectKey=NodeGoat -Dsonar.qualitygate.wait=true -Dsonar.sources=. -Dsonar.host.url=http://192.168.240.1:9000 -Dsonar.token=sqp_5e910736ca78be33740238ee6b64aba914f96a7e'
}
}
}
stage('Build Docker Image and Push to Docker Registry') {
agent {
docker {
image 'docker:dind'
args '--user root --network host -v /var/run/docker.sock:/var/run/docker.sock'
}
}
steps {
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
sh 'docker build -t alifadi/nodegoat:0.1 .'
sh 'docker push alifadi/nodegoat:0.1'
}
}
stage('Deploy Docker Image') {
agent {
docker {
image 'kroniak/ssh-client'
args '--user root --network host'
}
}
steps {
withCredentials([sshUserPrivateKey(credentialsId: "DeploymentSSHKey", keyFileVariable: 'keyfile')]) {
sh 'ssh -i ${keyfile} -o StrictHostKeyChecking=no [email protected] "echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin"'
sh 'ssh -i ${keyfile} -o StrictHostKeyChecking=no [email protected] docker pull alifadi/nodegoat:0.1'
sh 'ssh -i ${keyfile} -o StrictHostKeyChecking=no [email protected] docker rm --force nodegoat'
sh 'ssh -i ${keyfile} -o StrictHostKeyChecking=no [email protected] docker run -it --detach -p 4000:4000 --name nodegoat --network host alifadi/nodegoat:0.1'
}
}
}
stage('DAST Nuclei') {
agent {
docker {
image 'projectdiscovery/nuclei'
args '--user root --network host --entrypoint='
}
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh 'nuclei -u http://192.168.240.254:4000 -j > nuclei-report.json'
sh 'cat nuclei-report.json'
}
archiveArtifacts artifacts: 'nuclei-report.json'
}
}
// stage('DAST OWASP ZAP') {
// agent {
// docker {
// image 'owasp/zap2docker-stable:latest'
// args '-u root --network host -v /var/run/docker.sock:/var/run/docker.sock --entrypoint= -v .:/zap/wrk/:rw'
// }
// }
// steps {
// catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
// sh 'zap-full-scan.py -t http://192.168.1.84:4000 -r zapfull.html -x zapfull.xml'
// }
// sh 'cp /zap/wrk/zapfull.html ./zapfull.html'
// sh 'cp /zap/wrk/zapfull.xml ./zapfull.xml'
// archiveArtifacts artifacts: 'zapfull.html'
// archiveArtifacts artifacts: 'zapfull.xml'
// }
// }
}
// post {
// always {
// node('built-in') {
// sh 'curl -X POST http://localhost:8080/api/v2/import-scan/ -H "Authorization: Token 4352361ac0640d6cb3284e5354f194fc89344c14" -F "scan_type=Trufflehog Scan" -F "file=@./trufflehog-scan-result.json;type=application/json" -F "engagement=1"'
// sh 'curl -X POST http://localhost:8080/api/v2/import-scan/ -H "Authorization: Token 4352361ac0640d6cb3284e5354f194fc89344c14" -F "scan_type=Nuclei Scan" -F "file=@./nuclei-report.json;type=application/json" -F "engagement=1"'
// sh 'curl -X POST http://localhost:8080/api/v2/import-scan/ -H "Authorization: Token 4352361ac0640d6cb3284e5354f194fc89344c14" -F "scan_type=ZAP Scan" -F "file=@./zapfull.xml;type=text/xml" -F "engagement=1"'
// }
// }
// }
}