This repository has been archived by the owner on Nov 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
148 lines (132 loc) · 4.91 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
@Library('ecdc-pipeline')
import ecdcpipeline.ContainerBuildNode
import ecdcpipeline.PipelineBuilder
project = "nexus-constructor"
// Set number of old artefacts to keep.
properties([
buildDiscarder(
logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '1',
daysToKeepStr: '',
numToKeepStr: ''
)
)
])
container_build_nodes = [
'centos7': ContainerBuildNode.getDefaultContainerBuildNode('centos7-gcc11')
]
// JENKINS IS ONLY USED TO AUTOMATE THE FORMATTING AND UPDATING THE NEXUS DOCS
// THE ACTUALLY "BUILDING" IS DONE VIA GITHUB ACTIONS
pipeline_builder = new PipelineBuilder(this, container_build_nodes)
builders = pipeline_builder.createBuilders { container ->
pipeline_builder.stage("Checkout") {
dir(pipeline_builder.project) {
scm_vars = checkout scm
}
// Copy source code to container
container.copyTo(pipeline_builder.project, pipeline_builder.project)
} // stage
pipeline_builder.stage("${container.key}: Dependencies") {
container.sh """
which python
python --version
python -m pip install --user -r ${pipeline_builder.project}/requirements-dev.txt
python -m pip install --user -r ${pipeline_builder.project}/requirements-jenkins.txt
"""
} // stage
if (env.CHANGE_ID) {
pipeline_builder.stage("${container.key}: Formatting (black)") {
try {
container.sh """
cd ${pipeline_builder.project}
export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8
python -m black .
git config user.email '[email protected]'
git config user.name 'cow-bot'
git status -s
git add -u
git commit -m 'GO FORMAT YOURSELF (black)'
"""
} catch (e) {
// Okay to fail as there could be no badly formatted files to commit
} finally {
// Clean up
}
} // stage
}
// Only run in pull request builds
if (env.CHANGE_ID) {
def diffError = false
pipeline_builder.stage("Verify NeXus HTML") {
container.sh """
python -m venv nexus_doc_venv
source nexus_doc_venv/bin/activate
pip --proxy ${https_proxy} install --upgrade pip
pip --proxy ${https_proxy} install -r ${project}/definitions/requirements.txt
mkdir nexus_doc
cd nexus_doc
export SOURCE_DIR=../${project}/definitions
python ../${project}/definitions/utils/build_preparation.py ../${project}/definitions
make
"""
try {
container.sh """
diff \
--recursive \
${project}/nx-class-documentation/html \
nexus_doc/manual/build/html
"""
} catch (e) {
echo 'Caught exception after diff error, setting variable'
diffError = true
}
} // stage
if (diffError) {
pipeline_builder.stage("Update NeXus HTML") {
container.sh """
export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8
cd ${pipeline_builder.project}
rm -rf nx-class-documentation/html
cp -r ../nexus_doc/manual/build/html nx-class-documentation/
git config user.email '[email protected]'
git config user.name 'cow-bot'
git status --ignored
git add --all --force nx-class-documentation
git commit -m 'Update NeXus HTML documentation'
"""
// Push any changes resulting from formatting
container.copyFrom(pipeline_builder.project, 'clang-formatted-code')
withCredentials([
gitUsernamePassword(
credentialsId: 'cow-bot-username-with-token',
gitToolName: 'Default'
)
]) {
withEnv(["PROJECT=${pipeline_builder.project}"]) {
sh """
cd clang-formatted-code
git push https://github.com/ess-dmsc/${pipeline_builder.project}.git HEAD:$CHANGE_BRANCH
"""
} // withEnv
} // withCredentials
error 'Updating NeXus HTML documentation'
} // stage
} // if
} // if
}
node("docker") {
cleanWs()
stage('Checkout') {
dir("${project}") {
try {
scm_vars = checkout scm
} catch (e) {
failure_function(e, 'Checkout failed')
}
}
}
parallel builders
}