-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
164 lines (154 loc) · 6.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
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
164
pipeline {
parameters {
string(name: 'KUBE_DEV_NAMESPACE', description: 'Kubernetes Development Namespace', defaultValue: 'playcourt')
string(name: 'KUBE_PROD_NAMESPACE', description: 'Kubernetes Production Namespace', defaultValue: 'playcourt')
string(name: 'KUBE_DEV_URL', description: 'Kubernetes Development URL', defaultValue: 'https://console.playcourt.id')
string(name: 'DOCKER_PROD_REGISTRY_URL', description: 'docker registry', defaultValue: 'docker-registry-default.vsan-apps.playcourt.id')
string(name: 'DOCKER_DEV_REGISTRY_URL', description: 'docker registry', defaultValue: 'docker-registry-default.apps.playcourt.id')
string(name: 'SKIP_TLS', description: 'Skip TLS', defaultValue: 'true')
string(name: 'DOCKER_IMAGE_NAME', description: 'Docker Image Name', defaultValue: 'api-rest-playcourt')
string(name: 'DB_TEST_URL', description: 'DB Test URL', defaultValue: 'mongodb://localhost/db-test')
}
environment {
SECRET_KEY = 'secret'
DB_TYPE = 'mongo'
MONGO_URL_TEST = "${params.DB_TEST_URL}"
MYSQL_URL_TEST = 'mysql://root:qwerty445@localhost:3306/node-complete'
}
agent any
options {
skipDefaultCheckout()
}
stages {
stage('Cleaning Workspace') {
steps {
script {
echo 'Initializing for clean build...'
deleteDir()
}
}
}
stage('Checkout SCM') {
agent { label "agent-node-go" }
steps {
checkout scm
script {
echo "Checking-out SCM"
echo "get COMMIT_ID"
sh 'echo -n $(git rev-parse --short HEAD) > ./commit-id'
commitId = readFile('./commit-id')
sh 'printenv'
}
stash(name: 'ws', includes:'**,./commit-id')
}
}
stage('Initialize') {
parallel{
stage ("Agent: Nodejs"){
agent { label "agent-node-go" }
steps {
script {
echo 'Initializing...'
echo "Checking-up Environment"
sh "git --version"
sh "node --version"
sh "npm --version"
}
}
}
stage ("Agent: Docker"){
agent { label "agent-docker" }
steps {
script {
echo 'Initializing...'
echo "Checking-up Environment"
sh "git --version"
sh "docker --version"
}
}
}
}
}
stage('Unit Test') {
agent { label "agent-node-go" }
steps {
unstash 'ws'
script {
echo "Install Dependencies"
sh "npm install"
echo "Run Unit Test"
sh "npm test"
sh "npm run coverage"
}
}
}
stage('SonarQube Scan') {
when {
anyOf {
branch 'master'
branch 'development'
}
}
agent { label "agent-node-go" }
steps {
unstash 'ws'
echo "Run SonarQube"
script {
echo "Run SonarQube"
echo "defining sonar-scanner"
def scannerHome = tool 'SonarQube-Scanner' ;
withSonarQubeEnv('SonarQube') {
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
}
// stage('Build Images Docker') {
// parallel {
// stage('Build DEV') {
// // when {
// // branch 'develop'
// // }
// agent { label "agent-docker" }
// steps {
// unstash 'ws'
// script {
// echo "get COMMIT_ID"
// commitId = readFile('./commit-id')
// }
// sh 'rm -rf ./commit-id'
// sh "docker build --rm -t '${params.KUBE_DEV_NAMESPACE}/${params.DOCKER_IMAGE_NAME}:dev-${BUILD_NUMBER}-${commitId}' ."
// }
// }
// stage('Build PROD') {
// // when {
// // branch 'master'
// // }
// agent { label "agent-docker" }
// steps {
// unstash 'ws'
// script {
// echo "get COMMIT_ID"
// commitId = readFile('./commit-id')
// }
// sh 'rm -rf ./commit-id'
// sh "docker build --rm -t '${params.KUBE_PROD_NAMESPACE}/${params.DOCKER_IMAGE_NAME}:prod-${BUILD_NUMBER}-${commitId}' ."
// }
// }
// stage('Build Default') {
// agent { label "agent-docker" }
// steps {
// unstash 'ws'
// script {
// echo "get COMMIT_ID"
// commitId = readFile('./commit-id')
// }
// sh 'rm -rf ./commit-id'
// sh "docker build --rm -t '${params.KUBE_DEV_NAMESPACE}/${params.DOCKER_IMAGE_NAME}:${BUILD_NUMBER}-${commitId}' ."
// sh "docker rmi -f ${params.KUBE_DEV_NAMESPACE}/${params.DOCKER_IMAGE_NAME}:${BUILD_NUMBER}-${commitId}"
// }
// }
// }
// }
}
}