-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathJenkinsfile
More file actions
154 lines (142 loc) · 5.79 KB
/
Copy pathJenkinsfile
File metadata and controls
154 lines (142 loc) · 5.79 KB
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
pipeline {
agent { label 'worker' }
options {
timeout(time: 30, unit: 'MINUTES')
}
environment {
REPO_NAME = sh(returnStdout: true, script: 'basename `git remote get-url origin` .git').trim()
VERSION = sh(returnStdout: true, script: 'uv version --short').trim()
LATEST_AUTHOR = sh(returnStdout: true, script: 'git show -s --pretty=%an').trim()
LATEST_COMMIT_ID = sh(returnStdout: true, script: 'git describe --tags --long --always').trim()
PYTEST_TEST_OPTIONS = ' '
SNAPSHOT_BRANCH_REGEX = /(^main$)/
RELEASE_REGEX = /^([0-9]+(\.[0-9]+)*)(-(RC|beta-|alpha-)[0-9]+)?$/
RELEASE_DEPLOY = false
SNAPSHOT_DEPLOY = false
DOCKER_CREDENTIALS_ID = 'docker-heigit-ci-service'
}
stages {
stage('Build Backend') {
steps {
script {
echo REPO_NAME
echo LATEST_AUTHOR
echo LATEST_COMMIT_ID
echo env.BRANCH_NAME
echo env.BUILD_NUMBER
echo env.TAG_NAME
if (!(VERSION ==~ RELEASE_REGEX || VERSION ==~ /.*-SNAPSHOT$/)) {
echo 'Version:'
echo VERSION
error 'The version declaration is invalid. It is neither a release nor a snapshot.'
}
}
script {
sh 'uv sync --locked --only-group gdal-build-dependencies'
sh 'uv sync --locked'
sh 'uv run pybabel compile -d sketch_map_tool/translations'
sh 'wget --quiet -P weights https://downloads.ohsome.org/sketch-map-tool/weights/SMT-OSM.pt'
sh 'wget --quiet -P weights https://downloads.ohsome.org/sketch-map-tool/weights/SMT-ESRI.pt'
sh 'wget --quiet -P weights https://downloads.ohsome.org/sketch-map-tool/weights/SMT-CLS.pt'
}
}
post {
failure {
rocket_buildfail()
}
}
}
stage('Build Frontend') {
steps {
nodejs(nodeJSInstallationName: 'NodeJS 24') {
sh 'npm install'
sh 'npm run build'
}
}
post {
failure {
rocket_buildfail()
}
}
}
stage('Test') {
environment {
VIRTUAL_ENV="${WORKSPACE}/.venv"
PATH="${VIRTUAL_ENV}/bin:${PATH}"
}
steps {
script {
// run pytest
sh 'VCR_RECORD_MODE=none pytest --maxfail=1 --cov=sketch_map_tool --cov-report=xml tests'
// run static analysis with sonar-scanner
def scannerHome = tool 'SonarScanner 4'
withSonarQubeEnv('sonarcloud GIScience/ohsome') {
SONAR_CLI_PARAMETER =
"-Dsonar.python.coverage.reportPaths=${WORKSPACE}/coverage.xml " +
"-Dsonar.projectVersion=${VERSION}"
if (env.CHANGE_ID) {
SONAR_CLI_PARAMETER += ' ' +
"-Dsonar.pullrequest.key=${env.CHANGE_ID} " +
"-Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} " +
"-Dsonar.pullrequest.base=${env.CHANGE_TARGET}"
} else {
SONAR_CLI_PARAMETER += ' ' +
"-Dsonar.branch.name=${env.BRANCH_NAME}"
}
sh "${scannerHome}/bin/sonar-scanner " + SONAR_CLI_PARAMETER
}
// run other static code analysis and checks
sh 'prek run --all-files'
}
}
post {
failure {
rocket_testfail()
}
}
}
stage('Build and publish Docker image for main') {
agent {
kubernetes {
inheritFrom "BASE DOCKER"
}
}
when {
branch 'main'
}
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId: DOCKER_CREDENTIALS_ID, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'docker login -p $PASSWORD -u $USERNAME repo.heigit.org'
}
sh "docker build --push --builder=kube --platform=linux/amd64 -t repo.heigit.org/heigit/sketch-map-tool:main ."
}
}
}
stage('Build and publish Docker image for release') {
agent {
kubernetes {
inheritFrom "BASE DOCKER"
}
}
when {
buildingTag()
}
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId: DOCKER_CREDENTIALS_ID, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'docker login -p $PASSWORD -u $USERNAME repo.heigit.org'
}
sh "docker build --push --builder=kube --platform=linux/amd64 -t repo.heigit.org/heigit/sketch-map-tool:${env.TAG_NAME} ."
sh "docker build --push --builder=kube --platform=linux/amd64 -t repo.heigit.org/heigit/sketch-map-tool:latest ."
}
}
}
stage('Wrapping Up') {
steps {
encourage()
status_change()
}
}
}
}