-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
153 lines (137 loc) · 6.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
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
class Globals {
// the library version
static String version = 'latest'
// the tag used when publishing documentation
static String documentationTag = 'latest'
}
pipeline {
agent {label 'podman'}
parameters {
booleanParam(name: 'RELEASE_BUILD', defaultValue: false, description: 'Creates and publishes a new release')
booleanParam(name: 'PUBLISH_DOCUMENTATION', defaultValue: false, description: 'Publishes the generated documentation')
}
environment {
SCANNER_HOME = tool name: 'Sonarqube-certs-PROD', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
PATH = "$workspace/.venv-mchbuild/bin:$HOME/tools/openshift-client-tools:$HOME/tools/trivy:$PATH"
KUBECONFIG = "$workspace/.kube/config"
HTTP_PROXY = 'http://proxy.meteoswiss.ch:8080'
HTTPS_PROXY = 'http://proxy.meteoswiss.ch:8080'
NO_PROXY = '.meteoswiss.ch,localhost'
}
options {
gitLabConnection('CollabGitLab')
// New jobs should wait until older jobs are finished
disableConcurrentBuilds()
// Discard old builds
buildDiscarder(logRotator(artifactDaysToKeepStr: '7', artifactNumToKeepStr: '1', daysToKeepStr: '45', numToKeepStr: '10'))
// Timeout the pipeline build after 1 hour
timeout(time: 1, unit: 'HOURS')
}
stages {
stage('Init') {
steps {
sh '''
python -m venv .venv-mchbuild
PIP_INDEX_URL=https://hub.meteoswiss.ch/nexus/repository/python-all/simple \
.venv-mchbuild/bin/pip install --upgrade mchbuild
'''
updateGitlabCommitStatus name: 'Build', state: 'running'
}
}
stage('Test') {
parallel {
stage('python 3.10') {
steps {
sh 'mchbuild -s pythonImageName=\'"3.10"\' -s testReportName=junit-3.10.xml verify.unitWithoutCoverage'
}
}
stage('python 3.11') {
steps {
sh 'mchbuild -s pythonImageName=\'"3.11"\' -s testReportName=junit-3.11.xml verify.unitWithoutCoverage'
}
}
stage('python 3.12') {
steps {
sh 'mchbuild -s pythonImageName=\'"3.12"\' build test'
recordIssues(qualityGates: [[threshold: 10, type: 'TOTAL', unstable: false]], tools: [myPy(pattern: 'test_reports/mypy.log')])
}
}
}
post {
always {
junit keepLongStdio: true, testResults: 'test_reports/junit*.xml'
}
}
}
stage('Scan') {
steps {
echo("---- DEPENDENCIES SECURITY SCAN ----")
sh "mchbuild verify.securityScan"
echo("---- SONARQUBE ANALYSIS ----")
withSonarQubeEnv("Sonarqube-PROD") {
// fix source path in coverage.xml
// (required because coverage is calculated using podman which uses a differing file structure)
// https://stackoverflow.com/questions/57220171/sonarqube-client-fails-to-parse-pytest-coverage-results
sh "sed -i 's/\\/src\\/app-root/.\\//g' test_reports/coverage.xml"
sh "${SCANNER_HOME}/bin/sonar-scanner"
}
echo("---- SONARQUBE QUALITY GATE ----")
timeout(time: 1, unit: 'HOURS') {
// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
// true = set pipeline to UNSTABLE, false = don't
waitForQualityGate abortPipeline: true
}
}
}
stage('Release') {
when { expression { params.RELEASE_BUILD } }
steps {
echo 'Build a wheel and publish'
script {
withCredentials([string(credentialsId: 'python-mch-nexus-secret', variable: 'PYPIPASS')]) {
sh "PYPIUSER=python-mch mchbuild deploy.pypi"
Globals.version = sh(script: 'git describe --tags --abbrev=0', returnStdout: true).trim()
Globals.documentationTag = Globals.version
env.TAG_NAME = Globals.documentationTag
}
echo("---- PUBLISH DEPENDENCIES TO DEPENDENCY REGISTRY ----")
withCredentials([string(credentialsId: 'dependency-track-token-prod', variable: 'DTRACK_TOKEN')]) {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh "mchbuild verify.publishSbom -s version=${Globals.version}"
}
}
}
}
}
stage('Publish Documentation') {
when { expression { params.PUBLISH_DOCUMENTATION } }
steps {
withCredentials([string(credentialsId: 'documentation-main-prod-token',
variable: 'DOC_TOKEN')]) {
sh """
mchbuild -s pythonImageName=3.12 -s deploymentEnvironment=prod \
-s docVersion=${Globals.documentationTag} deploy.docs
"""
}
}
}
}
post {
aborted {
updateGitlabCommitStatus name: 'Build', state: 'canceled'
}
failure {
updateGitlabCommitStatus name: 'Build', state: 'failed'
echo 'Sending email'
emailext(subject: "${currentBuild.fullDisplayName}: ${currentBuild.currentResult}",
attachLog: true,
attachmentsPattern: 'generatedFile.txt',
body: "Job '${env.JOB_NAME} #${env.BUILD_NUMBER}': ${env.BUILD_URL}",
recipientProviders: [requestor(), developers()])
}
success {
echo 'Build succeeded'
updateGitlabCommitStatus name: 'Build', state: 'success'
}
}
}