forked from srayuso/unir-cicd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.long.groovy
152 lines (138 loc) · 4.2 KB
/
Jenkinsfile.long.groovy
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
pipeline {
agent {
label 'docker'
}
options {
timeout(time: 1, unit: 'HOURS')
}
triggers {
cron('H */1 * * 1-5')
pollSCM('H/10 * * * 1-5')
}
environment {
AN_ACCESS_KEY = credentials('my-predefined-secret-text')
PULL_REQUEST = "pr-${env.CHANGE_ID}"
IMAGE_TAG = "${env.PULL_REQUEST}"
}
stages {
stage('Summary') {
steps {
sh script: """
echo "GIT_BRANCH: ${GIT_BRANCH}"
echo "PULL_REQUEST: ${PULL_REQUEST}"
""", label: "Details summary"
}
}
stage('Static Analysis') {
parallel {
stage('Linting') {
agent {
dockerfile {
filename 'Dockerfile.custom'
dir 'ci'
label 'docker'
}
}
steps {
script {
sh "<run lint>"
}
}
}
stage('DevSecOps Static'){
steps {
echo "<run devsecops tests>"
}
}
}
}
stage('Build') {
agent {
docker {
image 'node:15.1.0-alpine3.10'
label 'docker'
}
}
steps {
sh "npm install"
sh "npm run build"
stash name: "DIST", includes: "dist/**"
stash name: "NODE_MODULES", includes: "node_modules/**"
archiveArtifacts artifacts: 'dist/**'
}
}
stage('Test') {
parallel {
stage('Unit Tests') {
steps {
unstash name: "NODE_MODULES"
sh "npm run test:unit"
junit 'tests/unit/reports/*.xml'
}
}
stage('Browser Tests') {
steps {
unstash name: "DIST"
unstash name: "NODE_MODULES"
sh "npm run test:cypress"
junit 'tests/cypress/reports/*.xml'
}
}
}
}
stage('Deploy') {
agent {
label "kubernetes"
}
when {
beforeAgent true
allOf {
equals expected: 'master', actual: BRANCH_NAME
equals expected: 'SUCCESS', actual: currentBuild.currentResult
}
}
steps {
unstash name: "DIST"
sh "docker build -t app:${env.GIT_COMMIT} ."
sh "docker push app:${env.GIT_COMMIT}"
script {
withCredentials([file(credentialsId: "K8S_CREDENTIALS", variable: 'KUBECTL_CONFIG_FILE')]) {
sh "kubectl apply --kubeconfig ${KUBECTL_CONFIG_FILE} -f deploy/template.yaml"
}
}
}
}
stage('DevSecOps Deploy'){
steps {
echo "<run devsecops tests>"
}
}
stage('Integration tests') {
when {
beforeAgent true
allOf {
equals expected: 'master', actual: BRANCH_NAME
equals expected: 'SUCCESS', actual: currentBuild.currentResult
}
}
steps {
sh "<run int tests>"
junit 'tests/integration/reports/*.xml'
}
}
}
post {
success {
emailext subject: "Pipeline successful", to: "devs@unir.net"
cleanWs()
}
unstable {
emailext subject: "Pipeline tests not successful", to: "devs@unir.net"
cleanWs()
}
failure {
emailext subject: "Pipeline error", to: "devops@unir.net,devs@unir.net"
cleanWs()
}
}
}