This repository has been archived by the owner on Sep 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jenkinsfile
81 lines (74 loc) · 2.1 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
#!/usr/bin/env groovy
pipeline {
agent {label 'formbox'}
options { disableConcurrentBuilds() }
tools {nodejs 'node6.11.3'}
environment {
DISABLE_SSL = 'true'
}
stages {
stage('Build') {
steps {
sh 'npm install'
sh 'npm run build-jenkins'
}
}
stage('Quality Gate') {
steps {
withEnv(['HOST=localhost', 'ASSETS=assets', 'CONFIG=config', 'DISABLE_SSL=true']) {
sh '''#!/bin/bash
CHECK="init"
while [ -n "$CHECK" ]; do
PORT=$(shuf -i 50000-51000 -n 1)
CHECK=$(netstat -a)
if [[ $CHECK != *"$PORT"* ]]; then
CHECK=""
fi
done
npm run test
'''
}
}
post {
always {
junit '.testresults/*.xml'
script {
if (GIT_BRANCH == 'master') {
withSonarQubeEnv('SonarQube') {
sh 'npm run sonar'
}
timeout(time: 1, unit: 'HOURS') {
script {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline abgebrochen auf Grund von Quality Gate Fehlern: ${qg.status}"
}
}
}
} else {
withSonarQubeEnv('SonarQube') {
withCredentials([usernamePassword(credentialsId: '3eaee9fd-bbdd-4825-a4fd-6b011f9a84c3', passwordVariable: 'GITHUB_ACCESS_TOKEN', usernameVariable: 'USER')]) {
sh "npm run sonar -- -Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=${env.CHANGE_ID} \
-Dsonar.github.repository=wollmux/formbox-api \
-Dsonar.github.oauth=${GITHUB_ACCESS_TOKEN}"
}
}
}
}
}
}
}
stage('Deploy') {
when {
branch 'master'
}
steps {
sh '''npm pack
mv formbox-api*.tgz /srv/formbox-api
cd /srv/formbox-api
npm install formbox-api*.tgz
pm2 restart formbox-api'''
}
}
}
}