-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
132 lines (117 loc) · 4.96 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
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-NWP-400-NAN-4-1-myftp-axel.eckenberg.git'
BIN_NAME = 'myftp'
}
stages {
stage('🕵️ Lint') {
steps {
// Clean before linting
cleanWs()
// Clone the repository
checkout scm
// 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]
echo "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') {
agent {
docker {
image 'epitechcontent/epitest-docker:latest'
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
steps {
ansiColor('xterm') {
// Run the build
sh 'make'
// Check file presence (e.g. binary, library, etc.)
script {
if (!fileExists(BIN_NAME)) {
error "The binary file does not exist"
}
}
// Archive the binary
archiveArtifacts BIN_NAME
}
}
}
stage ('🧪 Tests') {
steps {
ansiColor('xterm') {
// Run the tests
sh 'make tests_run'
// Update gcovr
sh 'python3 -m pip install -Iv gcovr==6.0'
// Run gcovr to generate the coverage report
sh 'gcovr --cobertura cobertura.xml --exclude tests/'
// Display the tests results in a graph using the JUnit plugin
junit(testResults: 'criterion.xml', allowEmptyResults : true)
// Display coverage using the Coverage plugin
recordCoverage(tools: [[parser: 'COBERTURA']],
id: 'cobertura', name: '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'
}
}
}