-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
98 lines (95 loc) · 2.58 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
pipeline {
agent {
kubernetes {
// Use of latests tag is not recomended
yaml '''
apiVersion: v1
kind: Pod
metadata:
spec:
containers:
- name: curl # to make requests
image: curlimages/curl
resources:
requests:
memory: "32Mi"
cpu: "100m"
limits:
memory: "32Mi"
cpu: "100m"
command:
- sleep
args:
- infinity
securityContext:
readOnlyRootFilesystem: true
- name: linter
image: stackrox/kube-linter:latest-alpine
imagePullPolicy: Always # to ensure we will always use the lastest version of the tool
resources:
requests:
memory: "32Mi"
cpu: "100m"
limits:
memory: "32Mi"
cpu: "100m"
command:
- sleep
args:
- infinity
securityContext:
readOnlyRootFilesystem: true
- name: trivy # image scanner
image: aquasec/trivy:latest-amd64
imagePullPolicy: Always # to ensure we will always use the lastest version of the tool
resources:
requests:
memory: "256Mi"
cpu: "200m"
limits:
memory: "512Mi"
cpu: "200m"
command:
- sleep
args:
- infinity
'''
}
}
stages {
stage('Syntax Scanning') {
steps {
container('linter') {
sh '/kube-linter lint files/'
}
}
}
stage('image Scanning') {
steps {
container('trivy') {
sh 'for f in files/*.yaml; \
do \
cat $f | grep "image:" | sed "s/^.*: //" >> images.txt; \
done'
sh 'while read i; do \
trivy image --timeout 30m0s "$i" --ignore-unfixed --exit-code 1 --severity CRITICAL; done < images.txt'
}
}
}
stage('Deploy'){
steps {
container('curl'){
sh 'for f in files/*.yaml; \
do \
curl \
--cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt \
--header "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" \
-X POST https://kubernetes.default.svc/api/v1/namespaces/devops-tools/pods \
-H "Content-Type: application/yaml" \
--data "$(cat $f)"; \
done'
}
}
}
}
}