-
Notifications
You must be signed in to change notification settings - Fork 58
/
Jenkinsfile
executable file
·128 lines (128 loc) · 2.43 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
pipeline {
environment {
registry = "<your-docker-hub-id>/my-cicd-app"
registryCredential = 'dockerhub'
dockerImage = ''
}
agent {
docker {
image 'python:alpine3.7'
args '-p 5000:5000'
}
}
stages {
stage('Build') {
steps {
sh 'pip install -r requirements.txt'
sh 'apk add libstdc++'
sh 'python ./app.py &'
}
}
stage('Test App') {
steps {
echo "${env.NODE_NAME}"
sh 'pwd'
sh 'uname -a'
sh 'python test.py'
}
post {
always {
junit 'test-reports/*.xml'
}
}
}
// Uncomment for SAST lab step
// Commented section starts
/*
stage('SAS Test') {
steps {
snykSecurity(
snykInstallation: 'SnykV2Plugin',
snykTokenId: 'snyktoken',
severity: 'medium',
failOnIssues: true)
}
}
*/
// Commented section ends
stage('Build image') {
steps{
script {
dockerImage = docker.build registry + ":$BUILD_NUMBER"
}
}
}
stage('Upload Image to Registry') {
steps{
script {
docker.withRegistry( '', registryCredential ) {
dockerImage.push()
}
}
}
}
stage('Remove Unused docker image') {
steps{
sh "docker rmi $registry:$BUILD_NUMBER"
}
}
// Uncomment for K8s app diployment step
// Commented section starts
/*
stage('Deploy Application') {
agent {
kubernetes {
cloud 'kubernetes'
}
}
steps {
container('kubectl') {
sh """cat <<EOF | kubectl apply --validate=false -f -
apiVersion: v1
kind: Namespace
metadata:
name: my-cicd-app
---
apiVersion: v1
kind: Service
metadata:
name: my-service
namespace: my-cicd-app
spec:
selector:
app: my-cicd-app
ports:
- protocol: TCP
port: 5000
targetPort: 5000
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-demo
namespace: my-cicd-app
spec:
replicas: 1
selector:
matchLabels:
app: my-cicd-app
template:
metadata:
labels:
app: my-cicd-app
spec:
containers:
- name: my-cicd-app
image: $registry:$BUILD_NUMBER
imagePullPolicy: Always
ports:
- containerPort: 5000
EOF"""
}
}
}
*/
// Commented section ends
}
}