-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfileParemeterized.ci
141 lines (126 loc) · 8.01 KB
/
JenkinsfileParemeterized.ci
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
def getBranchName(branch) {
return branch.replaceAll("/", "-").replaceAll(" ", "-").toLowerCase()
}
pipeline {
agent any
options {
disableConcurrentBuilds()
}
environment {
branch = getBranchName("${env.GIT_BRANCH}")
project = "kaleidos"
appName = "${env.JOB_NAME - ~/\/.*/}"
version = "${branch}-${env.BUILD_NUMBER}"
projectName = "${project}--${appName}--${version}"
HOME = "${WORKSPACE}"
NPM_CONFIG_CACHE = "${WORKSPACE}/.npm"
}
stages {
stage('DEBUG') {
steps {
sh "export HOST_UID_GID=\$(id -u):\$(id -g)"
sh "echo BUILDING BACKEND BRANCH"
sh "echo ${env.backendbranch}"
sh "echo BUILDING FRONTEND BRANCH"
sh "echo ${env.frontendbranch}"
}
}
stage('Linting') {
steps {
sh "export HOST_UID_GID=\$(id -u):\$(id -g)"
sh "npm install"
sh "npm run lint"
}
}
stage('Checkout project') {
steps {
sh "export HOST_UID_GID=\$(id -u):\$(id -g)"
sh "cp .dist.env .env"
sh "rm -rf kaleidos-project 2> /dev/null"
sh "git clone -b ${env.BACKENDBRANCH} https://github.com/kanselarij-vlaanderen/kaleidos-project.git"
}
}
stage('Prepare for automated tests') {
steps {
sh "export HOST_UID_GID=\$(id -u):\$(id -g)"
sh "cp ${env.WORKSPACE}/Dockerfile.ci ${env.WORKSPACE}/Dockerfile"
sh "cp ${env.WORKSPACE}/ci/docker-compose.override.yml ${env.WORKSPACE}/kaleidos-project/docker-compose.override.yml"
sh "cd ${WORKSPACE}/kaleidos-project && mkdir data -p && chmod 1777 -R data"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} pull"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} up -d --build"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T triplestore chmod -R 1777 /data"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T search chmod 1777 -R /data"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T file-bundling chmod 777 -R /share"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T docx-conversion chmod 777 -R /share"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T publication-report chmod 777 -R /share"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T decision-report-generation chmod 777 -R /share"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T minutes-report-generation chmod 777 -R /share"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T decision-extraction chmod 777 -R /share"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T document-stamping chmod 777 -R /share"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T draft-file chmod 777 -R /share"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T draft-file-mover chmod 777 -R /share"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T pdf-signature-remover chmod 777 -R /share"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T pdf-flattener chmod 777 -R /share"
sh "cp ${WORKSPACE}/ci/.env.cypress ${WORKSPACE}/.env.cypress"
// Wait for elasticsearch to have cerated the indices and stuff.
sh "sleep 45"
// Reset the contents of DB an search
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} kill elasticsearch search"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} rm -fs elasticsearch search"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} kill triplestore file docx-conversion forever-cache cache resource cache-warmup yggdrasil migrations publication-report decision-extraction decision-report-generation file-bundling minutes-report-generation document-stamping draft-file draft-file-mover pdf-signature-remover pdf-flattener"
sh "cd ${WORKSPACE}/kaleidos-project && rm -rf testdata && rm -rf testdata-elasticsearch"
sh "cd ${WORKSPACE}/kaleidos-project && unzip -o testdata.zip -d ${WORKSPACE}/kaleidos-project"
sh "cd ${WORKSPACE}/kaleidos-project && unzip -o testdata-elasticsearch.zip -d ${WORKSPACE}/kaleidos-project"
sh "cd ${WORKSPACE}/kaleidos-project && chmod 1777 -R testdata && chmod 1777 -R testdata-elasticsearch"
sh "cd ${WORKSPACE}/kaleidos-project && mv ${WORKSPACE}/kaleidos-project/testdata-elasticsearch/* ${WORKSPACE}/kaleidos-project/testdata"
sh "cd ${WORKSPACE}/kaleidos-project && chmod 1777 -R data"
sh "cd ${WORKSPACE}/kaleidos-project && rm -rf data/*"
sh "cd ${WORKSPACE}/kaleidos-project && cp -rf testdata/* data"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} up -d triplestore migrations cache forever-cache"
// cascaded startup, wait for migrations before warmup up cache
sh "sleep 30"
// up te system
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} up -d"
// Wait for indexation.
sh "sleep 600"
}
}
stage('Automated tests: Cypress') {
steps {
// sh "npx cypress run"
sh "export HOST_UID_GID=\$(id -u):\$(id -g)"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T e2e-electron cypress run"
// sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T e2e-electron cypress run --spec '**/e2e/*.spec.js'"
// sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} exec -T e2e-electron cypress run --spec '**/unit/search.spec.js'"
}
}
}
post {
always {
sh "mkdir -p ${WORKSPACE}/reports"
sh "mkdir -p ${WORKSPACE}/reports/cypress_screenshots/"
sh "touch ${WORKSPACE}/reports/cypress_screenshots/test.png"
sh "cp -rf ${WORKSPACE}/cypress/screenshots ${WORKSPACE}/reports/cypress_screenshots || true"
// Cypress reports and screenshots
archiveArtifacts allowEmptyArchive: true, artifacts: 'reports/cypress_screenshots/**/*.png'
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'reports', reportFiles: 'index.html', reportName: 'Build Reports', reportTitles: 'Build report'])
// Stack service logs
sh "mkdir -p ${WORKSPACE}/service-logs"
sh '''
cd $WORKSPACE/kaleidos-project &&
for container_name in $(docker compose -p $projectName ps | awk '{print $1}' | tail -n +3)
do
docker logs -t $container_name > $WORKSPACE/service-logs/$container_name.log 2>&1
done
'''
archiveArtifacts allowEmptyArchive: true, artifacts: 'service-logs/*.log'
}
cleanup {
sh "export HOST_UID_GID=\$(id -u):\$(id -g)"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} down -v"
sh "cd ${WORKSPACE}/kaleidos-project && docker compose -p ${projectName} rm -f"
sh "docker network prune -f"
cleanWs()
}
}
}