-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
executable file
·147 lines (135 loc) · 5.35 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
@Library('web-service-helper-lib') _
pipeline {
agent {
label 'docker && maven'
}
environment {
TARGET_PREFIX = 'e-learning-by-sse/nm-skill-service'
DOCKER_TARGET = "${TARGET_PREFIX}:unstable"
REMOTE_UPDATE_SCRIPT = '/staging/update-compose-project.sh nm-competence-repository'
NPMRC = 'e-learning-by-sse'
POSTGRES_DB = 'competence-repository-db'
POSTGRES_USER = 'postgres'
POSTGRES_PASSWORD = 'admin'
API_VERSION = packageJson.getVersion()
}
options {
ansiColor('xterm')
}
stages {
stage("Starting NodeJS Build") {
agent {
docker {
image 'node:18-bullseye'
reuseNode true
label 'docker'
args '--tmpfs /.cache -u root -v /var/run/docker.sock:/var/run/docker.sock '
}
}
stages {
stage("Prepare Build env") {
steps {
sh 'rm -rf output/'
sh 'rm -rf src/output/'
sh 'npm install'
sh 'apt update'
sh 'apt install -y docker.io'
}
}
stage('Build and Lint') {
steps {
sh 'npx prisma generate'
sh 'npm run build'
warnError('Linting failed') {
sh 'npm run lint:ci'
}
}
}
stage('Test') {
environment {
DB_URL = "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?schema=public"
SAVE_LOG_TO_FILE = true
LOG_LEVEL = "info"
PASSING_THRESHOLD = 0.5
BERUFENET_BASEURL="https://rest.arbeitsagentur.de/infosysbub/bnet/pc/v1"
BERUFENET_CLIENT_SECRET="infosysbub-berufenet"
BERUFENET_TIMEOUT=120000
}
steps {
script {
try {
withPostgres([ dbUser: env.POSTGRES_USER, dbPassword: env.POSTGRES_PASSWORD, dbName: env.POSTGRES_DB ]).insideSidecar('node:18-bullseye') {
sh 'mv .env env-settings.backup' // only use jenkins .env
sh 'npx prisma db push'
sh 'npm run test:jenkins'
sh 'mv env-settings.backup .env' // Restore .env
sh 'touch testfile.txt'
}
} catch(err) {
if (env.BRANCH_NAME == 'main') {
error('Stopping build on master branch due to test failures.')
} else {
unstable('Tests failed, but continuing build on development branches.')
}
}
}
}
post {
success {
// Test Results
junit 'output/test/junit*.xml'
// New Coverage Tool: Cobertura + Coverage Plugin
recordCoverage qualityGates: [[metric: 'LINE', threshold: 75.0], [metric: 'BRANCH', threshold: 60.0]], tools: [[parser: 'COBERTURA', pattern: 'src/output/test/coverage/cobertura-coverage.xml'], [parser: 'JUNIT', pattern: 'output/test/junit*.xml']]
}
}
}
stage('Docker Build') {
when {
branch 'main'
}
steps {
ssedocker {
create {
target "${env.DOCKER_TARGET}"
}
publish {}
}
}
}
}
}
stage('Starting Post Build Actions') {
parallel {
stage('Deploy Staging') {
when {
branch 'main'
}
steps {
staging01ssh env.REMOTE_UPDATE_SCRIPT
}
}
stage('Create Release (Swagger and Docker)') {
when {
buildingTag()
}
options {
timeout(time: 200, unit: 'SECONDS')
}
environment {
APP_URL = "http://localhost:3000/api-json"
}
steps {
ssedocker {
create {
target "${env.TARGET_PREFIX}:latest"
}
publish {
tag "${env.API_VERSION}"
}
}
}
}
}
}
}
}