This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Jenkinsfile
240 lines (212 loc) · 9.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
env.PYTHONUNBUFFERED = 1
env.ANSIBLE_CONFIG = '${WORKSPACE}/paas-ci/ansible.cfg'
env.PAAS_SLAVE = "paas-sig-ci-slave01"
env.BFS_PB = 'paas-ci/playbooks/openshift/bfs.yml'
env.CBS_PB = 'paas-ci/playbooks/openshift/cbs.yml'
env.TARGET_BASE_NAME = 'paas7-openshift-origin'
env.TARGET_SFX_NAME = 'el7'
env.PAAS_REPO = 'https://github.com/CentOS-PaaS-SIG/paas-sig-ci'
env.VENV = env.JOB_NAME + '-' + UUID.randomUUID().toString().substring(0,5)
properties(
[
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '25', daysToKeepStr: '', numToKeepStr: '50')),
disableConcurrentBuilds(),
parameters(
[
string(defaultValue: 'v3.11.0', description: 'origin version', name: 'ORIGIN_VERSION'),
string(defaultValue: 'openshift-ansible-3.11.115-1', description: 'openshift-ansible version', name: 'OA_VERSION'),
string(defaultValue: '', description: 'target in the CBS build system', name: 'BUILD_TARGET'),
booleanParam(defaultValue: true, description: 'build in CBS as a scratch build', name: 'SCRATCH'),
booleanParam(defaultValue: false, description: 'build from the master branch', name: 'BE'),
booleanParam(defaultValue: true, description: 'build origin', name: 'BUILD_ORIGIN'),
booleanParam(defaultValue: true, description: 'build openshift-ansible', name: 'BUILD_OA'),
],
),
pipelineTriggers([cron('H */3 * * *')]),
]
)
node (env.PAAS_SLAVE) {
def currentStage = ""
ansiColor('xterm') {
timestamps {
try {
deleteDir()
// set branch vars
if ("${env.BE}" == "true") {
ORIGIN_BRANCH = 'master'
OA_BRANCH = 'master'
} else {
ORIGIN_BRANCH = "${env.ORIGIN_VERSION}"
OA_BRANCH = "${env.OA_VERSION}"
}
if ("${env.BE}" == "true") {
env.BUILD_TARGET = 'paas7-openshift-future-el7'
}
currentStage = 'Provision-Node'
stage(currentStage) {
// Checkout this SCM
dir('paas-ci') {
checkout poll: false,
scm: [$class: 'GitSCM',
branches: [[name: "master"]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [
[
refspec: '+refs/tags/*:refs/remotes/origin/tags/* +refs/heads/master:refs/remotes/origin/master',
url: "${env.PAAS_REPO}"
]]]
}
duffyNode(currentStage, 'get')
}
currentStage = 'Build-Origin-SRPM'
stage(currentStage){
if ("${env.BUILD_ORIGIN}" == "true") {
currentBuild.displayName = "origin - ${ORIGIN_BRANCH}"
bfs(currentStage, 'origin')
} else {
echo "NOT Building origin"
currentBuild.displayName = "NOT building origin"
}
}
currentStage = 'Build-Openshift-Ansbile-SRPM'
stage(currentStage){
if ("${env.BUILD_OA}" == "true") {
if ("${env.BE}" == "true") {
currentBuild.displayName += " :: openshift-ansible - ${OA_BRANCH}"
} else {
currentBuild.displayName += " :: ${OA_BRANCH}"
}
bfs(currentStage, 'openshift-ansible')
} else {
echo "NOT Building openshift-ansible"
currentBuild.displayName += " :: NOT building openshift-ansible"
}
}
currentStage = 'cbs-origin'
stage(currentStage){
if ("${env.BUILD_ORIGIN}" == "true") {
cbs(currentStage, 'origin')
} else {
echo "NOT Building origin"
}
}
currentStage = 'cbs-openshift-ansible'
stage(currentStage){
if ("${env.BUILD_OA}" == "true") {
cbs(currentStage, 'openshift-ansible')
} else {
echo "NOT Building openshift-ansible"
}
}
} catch (e) {
// Set build result
currentBuild.result = 'FAILURE'
// Report the exception
echo "Error: Exception from " + currentStage + ":"
echo e.getMessage()
// Throw the error
throw e
} finally {
currentStage = 'Return-Node'
stage(currentStage) {
duffyNode(currentStage, 'done')
}
currentBuild.description = ''
if( fileExists("cbs_taskid_origin.groovy") ) {
currentBuild.description = "<a href=\"https://cbs.centos.org/koji/taskinfo?taskID=${env.CBS_TASKID_origin}\">origin_taskID = ${env.CBS_TASKID_origin}</a> :"
}
if( fileExists("cbs_taskid_openshift-ansible.groovy") ) {
currentBuild.description += ": <a href=\"https://cbs.centos.org/koji/taskinfo?taskID=${env.CBS_TASKID_openshift_ansible}\">O-A_taskID = ${env.CBS_TASKID_openshift_ansible}</a>"
}
// Archive our artifacts
step([$class: 'ArtifactArchiver', allowEmptyArchive: true, artifacts: '*.log,*.txt,*.groovy', fingerprint: true])
}
}
}
}
/**
* Method to get/release Duffy node
* @param stage - Current stage
* @param action - get or done
* @return
*/
def duffyNode (String stage, String action) {
echo "Currently in stage: ${stage}"
env.ACTION = action
sh '''
#!/bin/bash
set -xeuo pipefail
if [ "${ACTION}" == "get" ]; then
cico node get
cico inventory -c hostname -c comment -f csv --quote none 2>/dev/null | tail -1 | awk -F',' '{print $1}' > ${WORKSPACE}/duffy_host.inventory
cico inventory -c hostname -c comment -f csv --quote none 2>/dev/null | tail -1 | awk -F',' '{print $2}' > ${WORKSPACE}/duffy_ssid.inventory
DUFFY_HOST=$( cat ${WORKSPACE}/duffy_host.inventory )
sed -i "s/${DUFFY_HOST}//g" ~/.ssh/known_hosts
else
DUFFY_SSID=$( cat ${WORKSPACE}/duffy_ssid.inventory )
cico node done ${DUFFY_SSID}
fi
'''
}
/**
* Method to build origin or openshift-ansible from source
* @param stage - Current stage
* @param project - origin or openshift-ansible
* @return
*/
def bfs (String stage, String project) {
echo "Currently in stage: ${stage}"
env.PROJECT = project ?: 'origin'
bfsCommand = "ansible-playbook -u root -vv " +
"-i ${env.WORKSPACE}/duffy_host.inventory " +
"${env.WORKSPACE}/${env.BFS_PB} " +
"-e project=${project} " +
"-e bleeding_edge=${env.BE} " +
"-e clean=true "
if (env.PROJECT == 'origin') {
bfsCommand += "-e origin_version=${env.ORIGIN_VERSION}"
} else if (env.PROJECT == 'openshift-ansible') {
bfsCommand += "-e oa_version=${env.OA_VERSION} " +
"-e origin_version=${env.ORIGIN_VERSION}"
}
env.BFS_COMMAND = bfsCommand
sh '''
#!/bin/bash
set -xeuo pipefail
# see what we have in terms of inventory
${BFS_COMMAND}
'''
}
/**
* Method to build origin or openshift-ansible in cbs
* @param stage - Current stage
* @param project - origin or openshift-ansible
* @return
*/
def cbs (String stage, String project) {
echo "Currently in stage: ${stage}"
env.PROJECT = project ?: 'origin'
sh '''
#!/bin/bash
set -xeo pipefail
if [ "$BUILD_TARGET" == "" ] && [ "$BUILD_ORIGIN" == "true" ]; then
SHORT_VERSION=$( echo $ORIGIN_VERSION | awk -F'.' '{print $1$2}' | sed 's/v//' )
BUILD_TARGET="${TARGET_BASE_NAME}${SHORT_VERSION}-${TARGET_SFX_NAME}"
elif [ "$BUILD_TARGET" == "" ] && [ "$BUILD_OA" == "true" ]; then
SHORT_VERSION=$( echo $OA_VERSION | awk -F'.' '{print $1$2}' | sed 's/openshift-ansible-//' )
BUILD_TARGET="${TARGET_BASE_NAME}${SHORT_VERSION}-${TARGET_SFX_NAME}"
fi
# see what we have in terms of inventory
ansible-playbook -u root -vv \
-i $WORKSPACE/duffy_host.inventory \
$WORKSPACE/${CBS_PB} -e "project=${PROJECT}" \
-e "scratch=${SCRATCH}" \
-e "bleeding_edge=${BE}" \
-e "cbs_target=${BUILD_TARGET}"
'''
if( fileExists("cbs_taskid_${env.PROJECT}.groovy") ) {
load("cbs_taskid_${env.PROJECT}.groovy")
}
}