-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
240 lines (214 loc) · 9.62 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!groovy
/*
* Copyright (C) 2020 - present Juergen Zimmermann, Hochschule Karlsruhe
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// https://www.jenkins.io/doc/tutorials/create-a-pipeline-in-blue-ocean
pipeline {
// agent any
agent {
docker {
image 'node:23.7.0-bookworm'
// https://stackoverflow.com/questions/62330354/jenkins-pipeline-alpine-agent-apk-update-error-unable-to-lock-database-permis
// https://stackoverflow.com/questions/42630894/jenkins-docker-how-to-control-docker-user-when-using-image-inside-command/51986870#51986870
// https://stackoverflow.com/questions/42743201/npm-install-fails-in-jenkins-pipeline-in-docker
args '--publish 3000:3000 --publish 5000:5000'
// fuer "apt-get install ..."
args '--user root:root'
// node:...-bookworm : in /etc/passwd gibt es "node" mit uid=1000
//args '--user 1000:1000'
}
}
// Umgebungsvariable:
//environment {
// Cloud:
//DB_HOST = 'unknown.amazonaws.com'
//DB_USER = 'nobody'
//DB_PASS = 'ChangeMe'
//DB_POPULATE = true
//}
options {
// Timeout fuer den gesamten Job
timeout time: 60, unit: 'MINUTES'
}
stages {
// Stage = Logisch-zusammengehoerige Aufgaben der Pipeline:
// zur spaeteren Visualisierung
stage('Init') {
// Step = einzelne Aufgabe
steps {
script {
if (!isUnix()) {
error 'Unix ist erforderlich'
}
}
echo "Jenkins-Job ${env.JOB_NAME} #${env.BUILD_ID} mit Workspace ${env.WORKSPACE}"
// Unterverzeichnisse src und test im WORKSPACE loeschen: vom letzten Build
// Kurzform fuer: sh([script: '...'])
sh 'rm -rf src'
sh 'rm -rf __tests__'
sh 'rm -rf node_modules'
sh 'rm -rf dist'
sh 'rm -rf .extras/doc/api'
sh 'rm -rf .extras/doc/folien/folien.html'
sh 'rm -rf .extras/doc/projekthandbuch/html'
// https://www.jenkins.io/doc/pipeline/steps/git
// "named arguments" statt Funktionsaufruf mit Klammern
git url: 'https://github.com/juergenzimmermann/buch', branch: 'main', poll: true
}
}
stage('Install') {
steps {
// https://stackoverflow.com/questions/51416409/jenkins-env-node-no-such-file-or-directory
// https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions
// https://www.debian.org/distrib/packages
// https://packages.debian.org/buster/nodejs
sh 'id'
sh 'cat /etc/passwd'
sh 'echo $PATH'
sh 'pwd'
sh 'uname -a'
//sh 'lsb_release -a'
sh 'cat /etc/os-release'
sh 'cat /etc/debian_version'
sh 'apt-cache policy nodejs'
// https://github.com/nodesource/distributions#installation-instructions
// https://packages.debian.org/stable/python/python3
// https://packages.debian.org/bookworm/python3
// https://packages.debian.org/bookworm/python3-minimal
// https://packages.debian.org/trixie/python3.12
// https://computingforgeeks.com/how-to-install-python-on-debian-linux
// https://cloudcone.com/docs/article/how-to-install-python-3-10-on-debian-11
// https://linuxhint.com/install-python-debian-10
// https://computingforgeeks.com/how-to-install-python-on-debian-linux
// sh 'apt-get install --no-install-recommends --yes --show-progress gcc=4:12.2.0-3 g++=4:12.2.0-3 make=4.3-4.1 python3.11-minimal=3.11.2-6+deb12u4'
// sh 'apt show python3.11-minimal'
// sh 'apt-get install --no-install-recommends --yes --show-progress ca-certificates=20230311 curl=7.88.1-10+deb12u8 gnupg=2.2.40-1.1'
sh 'apt-get update --yes'
sh 'apt-get upgrade --yes'
sh 'python3 --version'
// https://www.debian.org/releases: Bookworm = Debian 12
// https://deb.nodesource.com hat nur node_20.x
// sh 'mkdir -p /etc/apt/keyrings'
// sh 'curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg'
// sh 'echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list'
// sh 'apt-get update'
// sh 'apt-get install nodejs --no-install-recommends --yes --show-progress'
// sh 'apt-cache policy nodejs'
sh 'node --version'
sh 'npm i -g npm'
sh 'npm --version'
script {
if (!fileExists("${env.WORKSPACE}/package.json")) {
error "package.json ist *NICHT* in ${env.WORKSPACE} vorhanden"
}
}
// /var/jenkins_home ist das Homedirectory vom User "jenkins"
// /var/jenkins_home/workspace/buch (siehe "pwd" oben)
sh 'cat package.json'
// Konfigurationsverzeichnis /root/.npm
sh 'npm ci --no-fund --no-audit'
}
}
stage('Compile') {
steps {
sh 'npx tsc --version'
// TODO Warum funktioniert npx nicht?
sh './node_modules/.bin/tsc'
}
}
stage('Test, Codeanalyse, Security, Dok.') {
steps {
parallel(
'Test': {
echo 'TODO: Rechnername/IP-Adresse des DB-Servers fuer Tests konfigurieren'
//sh 'npm run test:coverage'
},
'ESLint': {
sh 'npx eslint --version'
sh 'npm run eslint'
},
'Security Audit': {
echo 'TODO: "npm audit" schlaegt fehl: @nestjs/graphql -> subscriptions-transport-ws -> ws'
//sh 'npm audit --omit=dev'
},
'AsciiDoctor': {
sh 'npx asciidoctor --version'
sh 'npm run asciidoctor'
},
'reveal.js': {
sh 'npx asciidoctor-revealjs --version'
sh 'npm run revealjs'
},
'TypeDoc': {
sh 'npx typedoc --version'
sh 'npm run typedoc'
}
)
}
post {
always {
echo 'TODO: Links fuer Coverage und TypeDoc'
//publishHTML target : [
// reportDir: 'coverage',
// reportFiles: 'index.html',
// reportName: 'Coverage (Istanbul)',
// reportTitles: 'Coverage'
//]
publishHTML (target : [
reportDir: '.extras/doc/projekthandbuch/html',
reportFiles: 'projekthandbuch.html',
reportName: 'Projekthandbuch',
reportTitles: 'Projekthandbuch'
])
publishHTML target : [
reportDir: '.extras/doc/folien',
reportFiles: 'folien.html',
reportName: 'Folien (reveal.js)',
reportTitles: 'reveal.js'
]
publishHTML target : [
reportDir: '.extras/doc/api',
reportFiles: 'index.html',
reportName: 'TypeDoc',
reportTitles: 'TypeDoc'
]
}
success {
script {
if (fileExists("${env.WORKSPACE}/buch.zip")) {
sh 'rm buch.zip'
}
}
// https://www.jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#zip-create-zip-file
zip zipFile: 'buch.zip', archive: false, dir: 'dist'
// jobs/buch/builds/.../archive/buch.zip
archiveArtifacts 'buch.zip'
}
}
}
stage('Docker Image bauen') {
steps {
echo 'TODO: Docker-Image bauen und veroeffentlichen'
// sh 'docker buildx bake'
}
}
stage('Deployment fuer Kubernetes') {
steps {
echo 'TODO: Deployment fuer Kubernetes mit z.B. Ansible, Terraform'
}
}
}
}