Repository navigation
Expand file tree
/
Copy path.jenkins
More file actions
220 lines (201 loc) · 5.25 KB
/
Copy path.jenkins
File metadata and controls
220 lines (201 loc) · 5.25 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
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
currentBuild.displayName = "#${BUILD_NUMBER}"
if (env.GERRIT_CHANGE_SUBJECT) {
currentBuild.displayName += " - ${GERRIT_CHANGE_SUBJECT} (${GERRIT_CHANGE_NUMBER})"
}
if (env.GERRIT_REFNAME) {
currentBuild.displayName += " - ${GERRIT_REFNAME}"
}
def buildPrepare()
{
sh """
git clean -xdff
uv venv --seed --python 3.12
uv pip install wheel
uv pip install cmake>=2.28
"""
}
def buildPreset(String preset, Boolean archive = false)
{
sh """
. .venv/bin/activate
cmake --preset ${preset} -DCPACK_PACKAGE_VERSION=${env.PROJECT_DESCRIBE}
cmake --build --preset ${preset}
"""
if (archive) {
sh """
. .venv/bin/activate
cpack --preset ${preset} -G ZIP
"""
archiveArtifacts (
artifacts: "build/${preset}/soem-*.zip",
fingerprint: true
)
}
}
def dockerBuildArgs()
{
return '''\
--build-arg BUILDER_UID="$( id -u )" \
--build-arg BUILDER_GID="$( id -g )" \
--build-arg BUILDER_USER="$( id -un )" \
--build-arg BUILDER_GROUP="$( id -gn )" \
'''
}
def buildDocs()
{
sh """
. .venv/bin/activate
uv pip install -r docs/requirements.txt
cmake --preset docs
cmake --build --preset docs
"""
dir('build/docs') {
script {
def systemInformation = sh(script: 'cmake --system-information', returnStdout: true)
def versionLine = systemInformation =~ /CMAKE_PROJECT_VERSION:STATIC=(.*)/
if (versionLine) {
env.PROJECT_VERSION = versionLine[0][1].trim()
}
}
}
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: false,
reportDir: 'build/docs/docs/sphinx/html/',
reportFiles: 'index.html',
reportName: 'Documentation']
)
zip(dir: 'build/docs/docs/sphinx',
glob: 'html/**',
zipFile: "build/${env.PROJECT_PREFIX}-html.zip"
)
archiveArtifacts (
artifacts: "build/${env.PROJECT_PREFIX}-html.zip"
)
stash(
name: "sphinx-html",
includes: "build/${env.PROJECT_PREFIX}-html.zip"
)
}
def installSbomTools()
{
dir('rt-sbom') {
checkout scmGit(
branches: [[name: 'FETCH_HEAD']],
userRemoteConfigs: [[
credentialsId: 'b13fb601-0e11-4462-be4b-581c0dc1d845',
url: 'ssh://products.intra.rt-labs.com:29418/rt-sbom',
refspec: 'refs/tags/v0.2.0'
]]
)
sh """
. ../.venv/bin/activate
uv pip install .
"""
}
}
def sbomArchive(Map args)
{
def archive = args.archive
def prefix = args.prefix
def name = args.name
sh """
. ${env.WORKSPACE}/.venv/bin/activate
rt-sbom source ${archive} \
--inject sbom.spdx.json \
--source-dir ${prefix}/ \
--name "${name}" \
--version "${env.PROJECT_DESCRIBE}" \
--namespace "${env.PROJECT_SPDX_NAMESPACE}/"
"""
}
def gitArchive(Map args)
{
def ref = args.ref
def name = args.name
def prefix = "${env.PROJECT_PREFIX}-${name}"
sh """
git archive ${ref} \
--output ${prefix}.zip \
--prefix ${prefix}/
"""
sbomArchive(
archive: "${prefix}.zip",
prefix: "${prefix}",
name: "${env.PROJECT_NAME}-${name}"
)
archiveArtifacts (
artifacts: "${prefix}.zip"
)
}
pipeline {
agent any
stages {
stage('prepare') {
steps {
script {
env.PROJECT_NAME = "soem"
env.PROJECT_DESCRIBE = sh(
script: "git describe --tags --always --dirty --match 'v*'",
returnStdout: true
).trim()
env.PROJECT_PREFIX = "${env.PROJECT_NAME}-${env.PROJECT_DESCRIBE}"
env.PROJECT_ORGANIZATION = "RT-Labs AB"
env.PROJECT_SPDX_NAMESPACE = "https://rt-labs.com/spdx/${env.PROJECT_NAME}/${env.PROJECT_DESCRIBE}"
}
}
}
stage("build") {
parallel {
stage('linux') {
steps {
buildPrepare()
buildPreset('default', true)
// buildPreset('test')
// buildDocs()
}
}
stage('linux-arm64') {
agent {
dockerfile {
filename 'linux-arm64.Dockerfile'
dir '.docker'
additionalBuildArgs dockerBuildArgs()
}
}
steps {
buildPrepare()
buildPreset('default', true)
}
}
stage('windows-x64') {
agent {
dockerfile {
filename 'windows-x64.Dockerfile'
dir '.docker'
additionalBuildArgs dockerBuildArgs()
}
}
steps {
buildPrepare()
buildPreset('default', true)
}
}
}
}
stage('archive') {
steps {
installSbomTools()
gitArchive(
ref: 'HEAD',
name: "src"
)
gitArchive(
ref: 'HEAD:samples',
name: "samples"
)
}
}
}
}