forked from centreon/centreon-gorgone
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
118 lines (110 loc) · 3.19 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
/*
** Variables.
*/
def serie = '22.04'
def maintenanceBranch = "${serie}.x"
def qaBranch = "dev-${serie}.x"
env.REF_BRANCH = 'master'
env.PROJECT='centreon-gorgone'
if (env.BRANCH_NAME.startsWith('release-')) {
env.BUILD = 'RELEASE'
} else if ((env.BRANCH_NAME == env.REF_BRANCH) || (env.BRANCH_NAME == maintenanceBranch)) {
env.BUILD = 'REFERENCE'
} else if ((env.BRANCH_NAME == 'develop') || (env.BRANCH_NAME == qaBranch)) {
env.BUILD = 'QA'
} else {
env.BUILD = 'CI'
}
def buildBranch = env.BRANCH_NAME
if (env.CHANGE_BRANCH) {
buildBranch = env.CHANGE_BRANCH
}
/*
** Functions
*/
def isStableBuild() {
return ((env.BUILD == 'REFERENCE') || (env.BUILD == 'QA'))
}
def checkoutCentreonBuild(buildBranch) {
def getCentreonBuildGitConfiguration = { branchName -> [
$class: 'GitSCM',
branches: [[name: "refs/heads/${branchName}"]],
doGenerateSubmoduleConfigurations: false,
userRemoteConfigs: [[
$class: 'UserRemoteConfig',
url: "ssh://git@github.com/centreon/centreon-build.git"
]]
]}
dir('centreon-build') {
try {
checkout(getCentreonBuildGitConfiguration(buildBranch))
} catch(e) {
echo "branch '${buildBranch}' does not exist in centreon-build, then fallback to master"
checkout(getCentreonBuildGitConfiguration('master'))
}
}
}
/*
** Pipeline code.
*/
stage('Deliver sources // Sonar analysis') {
node {
checkoutCentreonBuild(buildBranch)
dir('centreon-gorgone') {
checkout scm
}
sh "./centreon-build/jobs/gorgone/${serie}/gorgone-source.sh"
source = readProperties file: 'source.properties'
env.VERSION = "${source.VERSION}"
env.RELEASE = "${source.RELEASE}"
withSonarQubeEnv('SonarQubeDev') {
sh "./centreon-build/jobs/gorgone/${serie}/gorgone-analysis.sh"
}
timeout(time: 10, unit: 'MINUTES') {
def qualityGate = waitForQualityGate()
if (qualityGate.status != 'OK') {
currentBuild.result = 'FAIL'
}
}
}
}
try {
stage('RPM Packaging') {
parallel 'Packaging centos7': {
node {
checkoutCentreonBuild(buildBranch)
sh "./centreon-build/jobs/gorgone/${serie}/gorgone-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(buildBranch)
sh "./centreon-build/jobs/gorgone/${serie}/gorgone-package.sh alma8"
archiveArtifacts artifacts: 'rpms-alma8.tar.gz'
stash name: "rpms-alma8", includes: 'output/noarch/*.rpm'
sh 'rm -rf output'
}
}
if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
error('Package stage failure.');
}
}
if ((env.BUILD == 'RELEASE') || (env.BUILD == 'QA') || (env.BUILD == 'CI')) {
stage('Delivery') {
node {
checkoutCentreonBuild(buildBranch)
unstash 'rpms-alma8'
unstash 'rpms-centos7'
sh "./centreon-build/jobs/gorgone/${serie}/gorgone-delivery.sh"
}
if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
error('Delivery stage failure.');
}
}
}
} catch(e) {
currentBuild.result = 'FAILURE'
}