-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
167 lines (148 loc) · 6.3 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
pipeline {
agent any
environment {
// Set the ssh key for the mirror using secret private key
PRIVATE_KEY = credentials('EPITECH_SSH_KEY')
PUBLIC_KEY = credentials('EPITECH_SSH_PUBKEY')
MIRROR_URL = '[email protected]:EpitechPromo2027/B-OOP-400-NAN-4-1-raytracer-quentin.tennerel.git'
BIN_NAME = 'raytracer'
}
stages {
stage('📥 Checkout') {
steps {
// Clean before checkout
cleanWs()
// Clone the repository
checkout scm
}
}
stage('🕵️ Lint') {
steps {
// Run docker container
sh 'docker run --rm --security-opt "label:disable" -v "$(pwd)":"/mnt/delivery" -v "$(pwd)":"/mnt/reports" ghcr.io/epitech/coding-style-checker:latest "/mnt/delivery" "/mnt/reports"'
// Parse the report and fail the build if the quality gate is not passed
script {
def report = readFile 'coding-style-reports.log'
def errors = report.readLines()
for (error in errors) {
def file = error.split(':')[0]
def line = error.split(':')[1]
def type = error.split(':')[2]
def code = error.split(':')[3]
unstable "File: ${file}, Line: ${line}, Type: ${type}, Code: ${code}"
}
// Archive the report
archiveArtifacts 'coding-style-reports.log'
// Publish the report
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: true, reportDir: '.', reportFiles: 'coding-style-reports.log', reportName: 'Coding Style Report', reportTitles: ''])
// Fail the build if the quality gate is not passed
if (errors.size() > 0) {
// If on main branch, fail the build otherwise just warn
if (env.BRANCH_NAME == 'main') {
error "Too many coding style errors"
}
else {
unstable "Too many coding style errors"
}
}
}
}
}
stage('🏗️ Build') {
steps {
ansiColor('xterm') {
// Clean before building
sh 'make fclean'
// Run the build
sh 'make'
// Check file presence (e.g. binary, library, etc.)
script {
def BIN_NAMES = ['raytracer']
for (BIN_NAME in BIN_NAMES) {
if (!fileExists(BIN_NAME)) {
error "The binary file ${BIN_NAME} does not exist"
} else {
echo "The binary file ${BIN_NAME} exists"
archiveArtifacts artifacts: "${BIN_NAME}", fingerprint: true
}
}
}
}
}
}
stage ('🔎 Verify') {
steps {
script {
if (!fileExists(BIN_NAME)) {
error "The binary file does not exist"
}
}
}
}
stage('📦 Archive') {
steps {
archiveArtifacts BIN_NAME
}
}
stage ('🧪 Tests') {
steps {
// Run the tests
sh 'make tests_run'
// Update gcovr
sh 'python3 -m pip install -Iv gcovr==6.0'
script {
def dirs = ['libs/json']
for (dir in dirs) {
junit(testResults: "${dir}/criterion.xml", allowEmptyResults : true)
}
junit(testResults: "criterion.xml", allowEmptyResults : true)
}
sh 'gcovr --cobertura cobertura.xml --exclude tests/ --exclude libs/'
recordCoverage(tools: [[parser: 'COBERTURA']],
id: "coverage", name: "Coverage",
sourceCodeRetention: 'EVERY_BUILD')
script {
def dirs = ['libs/json']
for (d in dirs) {
dir(d) {
sh "gcovr --cobertura cobertura.xml --exclude tests/ --exclude libs/"
def coverage_id = d.replaceAll('/', '-') + "-coverage"
recordCoverage(tools: [[parser: 'COBERTURA']], sourceDirectories: [[path: "${d}/**"]],
id: coverage_id, name: "${d} Coverage",
sourceCodeRetention: 'EVERY_BUILD')
}
}
}
}
}
stage('🪞 Mirror') {
when {
branch 'main'
}
steps {
// Remove the mirror if it already exists
sh "git remote remove mirror || true"
// Add the mirror
sh "git remote add mirror ${MIRROR_URL}"
// Switch to the main branch
sh "git checkout main"
// Setup the ssh key for the mirror
withCredentials([sshUserPrivateKey(credentialsId: 'EPITECH_SSH_KEY', keyFileVariable: 'PRIVATE_KEY')]) {
sh 'GIT_SSH_COMMAND="ssh -i $PRIVATE_KEY" git push --mirror mirror'
}
}
}
}
post {
// Clean after build
always {
cleanWs(cleanWhenNotBuilt: true,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true,
patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
[pattern: '.propsfile', type: 'EXCLUDE']])
sh 'make fclean'
}
}
}