forked from paroksh/govwa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
163 lines (128 loc) · 6.05 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
pipeline {
agent any
// If anything fails, the whole Pipeline stops.
stages {
stage('Checkout'){
agent {
docker {
image 'golang'
args ' -u 0 -v ${WORKSPACE}:/go/src/govwa:rw'
}
}
steps {
git(url: 'https://github.com/snehakokil/govwa.git', branch: 'master')
stash name:'dockerfile', includes: '**/Dockerfile'
}
}
// Use golang.
stage('Build') {
agent {
docker {
image 'golang'
args ' -u 0 -v ${WORKSPACE}:/go/src/govwa:rw'
}
}
steps {
sh 'cd /go/src'
sh 'go get github.com/go-sql-driver/mysql'
sh 'go get github.com/gorilla/sessions'
sh 'go get github.com/julienschmidt/httprouter'
// Build the app.
sh 'go build'
stash name:'CompiledSource', includes:'**/**'
}
}
stage('Build-time SCA') {
agent {
docker {
image 'golang'
args ' -u 0 -v ${WORKSPACE}:/go/src/govwa:rw'
}
}
steps {
sh 'go get github.com/divan/depscheck'
sh 'cd /go/src'
sh 'go get github.com/go-sql-driver/mysql'
sh 'go get github.com/gorilla/sessions'
sh 'go get github.com/julienschmidt/httprouter'
sh 'depscheck -v . | tee depcheck.txt'
archiveArtifacts 'depcheck.txt'
}
}
stage('Build-time SAST') {
agent {
docker {
image 'golang'
args ' -u 0 -v ${WORKSPACE}:/go/src/govwa:rw'
}
}
steps {
sh 'cd /go/src'
sh 'go get github.com/go-sql-driver/mysql'
sh 'go get github.com/gorilla/sessions'
sh 'go get github.com/julienschmidt/httprouter'
echo 'cloning Gosec'
sh 'curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $GOPATH/bin'
echo 'listing current folder contents for verification'
sh 'cd /go/src/govwa'
echo 'SAST running with GOSEC'
script {
def status = sh returnStatus: true, script:'gosec -fmt=json -out=results.json ./...'
echo 'printing results'
archiveArtifacts '*.json'
print "SAST scanning complete"
if(status != 0) {
input message: 'SAST results violate severity threshold. Do you want to proceed?', submitter: 'ciuser'
}
} //end script
}
}
stage('Test-Time Checks'){
parallel {
stage('Deploy') {
agent {
docker {
image 'golang'
//for cache error
args '--name GoContainer --network=host -d -e XDG_CACHE_HOME=$GO_CACHE -v ${WORKSPACE}:/go/src/govwa'
}
}
steps {
sh 'go env'
sh 'cd /go/src/'
sh 'go get github.com/go-sql-driver/mysql'
sh 'go get github.com/gorilla/sessions'
sh 'go get github.com/julienschmidt/httprouter'
sh 'go run app.go &'
input message: 'Please review DAST results before proceeding.', submitter: 'ciuser'
}
}
stage('DAST'){
agent {
docker {
image 'owasp/zap2docker-stable'
args ' --network=host -u 0 -v /var/lib/jenkins/workspace/govwa:/zap/wrk:rw '
}
}
steps {
script{
try {
//sh 'zap.sh -daemon -port 2375 -host 127.0.0.1 -config api.disablekey=true -config scanner.attackOnStart=true -config view.mode=attack -config connection.dnsTtlSuccessfulQueries=-1 -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true &'
sh 'zap-cli -p 2375 status -t 120 && zap-cli -p 2375 open-url http://localhost:8082/'
sh 'zap-cli -p 2375 spider http://localhost:8082/'
sh 'zap-cli -p 2375 active-scan -r http://localhost:8082/'
sh 'zap-cli -p 2375 report --output-format html --output owasp-zap.html'
//sh 'zap-cli -p 8090 -v quick-scan -sc -o \'-config api.disablekey=true\' http://localhost:8082/ | tee zap.txt'
echo 'zap complete'
archiveArtifacts 'owasp-zap.html'
}
catch (err) {
echo "Caught: ${err}"
}
} //end script
} //end steps
}
}
}
}
}