This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
207 lines (193 loc) · 6.4 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
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
/*
** Variables.
*/
def serie = '22.10'
def stableBranch = "master"
def devBranch = "develop"
env.REF_BRANCH = 'master'
env.PROJECT='centreon-awie'
if (env.BRANCH_NAME.startsWith('release-')) {
env.BUILD = 'RELEASE'
env.REPO = 'testing'
} else if (env.BRANCH_NAME == stableBranch) {
env.BUILD = 'REFERENCE'
} else if (env.BRANCH_NAME == devBranch) {
env.BUILD = 'QA'
env.REPO = 'unstable'
} else {
env.BUILD = 'CI'
}
env.BUILD_BRANCH = env.BRANCH_NAME
if (env.CHANGE_BRANCH) {
env.BUILD_BRANCH = env.CHANGE_BRANCH
}
/*
** Functions
*/
def isStableBuild() {
return ((env.BUILD == 'REFERENCE') || (env.BUILD == 'QA'))
}
def checkoutCentreonBuild() {
dir('centreon-build') {
checkout resolveScm(
source: [
$class: 'GitSCMSource',
remote: 'https://github.com/centreon/centreon-build.git',
credentialsId: 'technique-ci',
traits: [[$class: 'jenkins.plugins.git.traits.BranchDiscoveryTrait']]
],
targets: [env.BUILD_BRANCH, 'master']
)
}
}
/*
** Pipeline code.
*/
stage('Deliver sources') {
node {
checkoutCentreonBuild()
dir('centreon-awie') {
checkout scm
}
sh "./centreon-build/jobs/awie/${serie}/mon-awie-source.sh"
source = readProperties file: 'source.properties'
env.VERSION = "${source.VERSION}"
env.RELEASE = "${source.RELEASE}"
publishHTML([
allowMissing: false,
keepAll: true,
reportDir: 'summary',
reportFiles: 'index.html',
reportName: 'Centreon AWIE Build Artifacts',
reportTitles: ''
])
}
}
try {
stage('Unit tests // RPM Packaging // Sonar analysis') {
parallel 'unit tests centos7': {
node {
checkoutCentreonBuild()
sh "./centreon-build/jobs/awie/${serie}/mon-awie-unittest.sh centos7"
if (currentBuild.result == 'UNSTABLE')
currentBuild.result = 'FAILURE'
if (env.CHANGE_ID) { // pull request to comment with coding style issues
ViolationsToGitHub([
repositoryName: 'centreon-awie',
pullRequestId: env.CHANGE_ID,
createSingleFileComments: true,
commentOnlyChangedContent: true,
commentOnlyChangedFiles: true,
keepOldComments: false,
commentTemplate: "**{{violation.severity}}**: {{violation.message}}",
violationConfigs: [
[parser: 'CHECKSTYLE', pattern: '.*/codestyle-be.xml$', reporter: 'Checkstyle']
]
])
}
recordIssues(
enabledForFailure: true,
qualityGates: [[threshold: 1, type: 'DELTA', unstable: false]],
tool: phpCodeSniffer(id: 'phpcs', name: 'phpcs', pattern: 'codestyle-be.xml'),
trendChartType: 'NONE',
referenceJobName: 'centreon-awie/master'
)
withSonarQubeEnv('SonarQubeDev') {
sh "./centreon-build/jobs/awie/${serie}/mon-awie-analysis.sh"
}
timeout(time: 10, unit: 'MINUTES') {
def qualityGate = waitForQualityGate()
if (qualityGate.status != 'OK') {
currentBuild.result = 'FAIL'
}
}
}
},
'Packaging centos7': {
node {
checkoutCentreonBuild()
sh "./centreon-build/jobs/awie/${serie}/mon-awie-package.sh centos7"
archiveArtifacts artifacts: 'rpms-centos7.tar.gz'
stash name: "rpms-centos7", includes: 'output/noarch/*.rpm'
sh 'rm -rf output'
}
},
'Packaging alma8': {
node {
checkoutCentreonBuild()
sh "./centreon-build/jobs/awie/${serie}/mon-awie-package.sh alma8"
archiveArtifacts artifacts: 'rpms-alma8.tar.gz'
stash name: "rpms-alma8", includes: 'output/noarch/*.rpm'
sh 'rm -rf output'
}
},
'Debian bullseye packaging and signing': {
node {
dir('centreon-awie') {
checkout scm
}
sh 'docker run -i --entrypoint "/src/centreon-awie/ci/scripts/centreon-awie-package.sh" -v "$PWD:/src" -e "DISTRIB=bullseye" -e "VERSION=$VERSION" -e "RELEASE=$RELEASE" registry.centreon.com/centreon-debian11-dependencies:22.10'
stash name: 'Debian11', includes: '*.deb'
archiveArtifacts artifacts: "*"
}
}
if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
error('Unit tests stage failure.');
}
}
stage('Docker creation') {
parallel 'Docker centos7': {
node {
checkoutCentreonBuild()
sh 'rm -rf output'
unstash 'rpms-centos7'
sh "./centreon-build/jobs/awie/${serie}/mon-awie-bundle.sh centos7"
}
}
if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
error('Bundle stage failure.');
}
}
stage('Acceptance tests') {
parallel 'centos7': {
node {
checkoutCentreonBuild()
sh "./centreon-build/jobs/awie/${serie}/mon-awie-acceptance.sh centos7"
junit 'xunit-reports/**/*.xml'
if (currentBuild.result == 'UNSTABLE')
currentBuild.result = 'FAILURE'
archiveArtifacts allowEmptyArchive: true, artifacts: 'acceptance-logs/*.txt, acceptance-logs/*.png'
}
}
if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
error('Acceptance tests stage failure.');
}
}
if ((env.BUILD == 'RELEASE') || (env.BUILD == 'QA')) {
stage('Delivery') {
node {
checkoutCentreonBuild()
unstash 'rpms-alma8'
unstash 'rpms-centos7'
sh "./centreon-build/jobs/awie/${serie}/mon-awie-delivery.sh"
withCredentials([usernamePassword(credentialsId: 'nexus-credentials', passwordVariable: 'NEXUS_PASSWORD', usernameVariable: 'NEXUS_USERNAME')]) {
checkout scm
unstash "Debian11"
sh '''for i in $(echo *.deb)
do
curl -u $NEXUS_USERNAME:$NEXUS_PASSWORD -H "Content-Type: multipart/form-data" --data-binary "@./$i" https://apt.centreon.com/repository/22.10-$REPO/
done
'''
}
}
if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
error('Delivery stage failure.');
}
}
}
} catch(e) {
if ((env.BUILD == 'RELEASE') || (env.BUILD == 'REFERENCE')) {
slackSend channel: "#monitoring-metrology", color: "#F30031", message: "*FAILURE*: `CENTREON AWIE` <${env.BUILD_URL}|build #${env.BUILD_NUMBER}> on branch ${env.BRANCH_NAME}\n*COMMIT*: <https://github.com/centreon/centreon-awie/commit/${source.COMMIT}|here> by ${source.COMMITTER}\n*INFO*: ${e}"
}
currentBuild.result = 'FAILURE'
}