This repository was archived by the owner on Dec 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.jenkinsfile
145 lines (123 loc) · 5.74 KB
/
main.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
#!/usr/bin/env groovy
/***************************************************************************
*
* (C) Copyright IBM Corp. 2018
*
* This program and the accompanying materials are made available
* under the terms of the Apache License v2.0 which accompanies
* this distribution.
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* Contributors:
* Multiple authors (IBM Corp.) - initial implementation and documentation
***************************************************************************/
properties([
parameters([
choice(name: 'CITGM_LOGLEVEL', choices: 'verbose\ninfo\nwarn\nsilly\nerror', defaultValue: 'verbose', description: 'This defines log level for CITGM.'),
string(defaultValue: "module-curation.eu-gb.mybluemix.net", description: 'module-curation-development.stage1.eu-gb.mybluemix.net || module-curation.eu-gb.mybluemix.net || IP:PORT', name: 'HOST'),
string(defaultValue: "refs/heads/master", description: 'The remote portion of the Git refspec to fetch and test PR - refs/pull/PR_NUMBER/head', name: 'GIT_REMOTE_REF'),
string(name: 'STARTFROM', defaultValue: '1', description: '''Where to start from: 1=PRE-CLEANUP, 2=MC-CITGM, 3=MC-License, 4=POST-CLEANUP''')
]),
])
withCredentials([usernamePassword(credentialsId: 'fb878c0f-2ce4-4759-9953-cfc36d59cf9b',
usernameVariable: 'API_USERNAME', passwordVariable: 'PASSWORD')]) {
def STARTFROM = params.STARTFROM.toInteger()
stage('PRE-CLEANUP') { if (STARTFROM <= 1) {
node ('linux && x64') {
checkout scm
withEnv(["HOST=${params.HOST}", "API_USERNAME=${env.API_USERNAME}", "PASSWORD=${env.PASSWORD}", "GIT_REMOTE_REF=${params.GIT_REMOTE_REF}"]){
env.citgm_parameters = sh (
script: "./clean-data.sh"
)
}
}
} }
stage('MC-CITGM (Test + Coverage)') { if (STARTFROM <= 2) {
/* - Check for new node/module version and add them to the database
- Find missing test results and return params for MC-CITGM */
node ('linux && x64') {
checkout scm
withEnv(["HOST=${params.HOST}", "API_USERNAME=${env.API_USERNAME}", "PASSWORD=${env.PASSWORD}", "GIT_REMOTE_REF=${params.GIT_REMOTE_REF}"]){
env.citgm_parameters = sh (
returnStdout: true,
script: "./missing-test.sh"
)
}
}
println "\n\n${env.citgm_parameters}\n\n"
def resp = env.citgm_parameters.trim().tokenize('%') // Create an array of parameters
// Create an array of buildJobs to run in parallel
def buildJobs = [:]
resp.each { str ->
def p = str.tokenize(',')
def module = "${p[0]}", module_version = "${p[1]}", node_version = "${p[2]}"
def os = "${p[3]}", arch = "${p[4]}", distro = "${p[5]}"
def parameters = []
parameters.push(string(name: 'MODULE', value: module))
parameters.push(string(name: 'MODULE_VERSION', value: module_version))
parameters.push(string(name: 'NODE_VERSION', value: node_version))
parameters.push(string(name: 'HOST', value: params.HOST))
parameters.push(string(name: 'OSS', value: os))
parameters.push(string(name: 'ARCHS', value: arch))
parameters.push(string(name: 'DISTROS', value: distro))
parameters.push(string(name: 'GIT_REMOTE_REF', value: params.GIT_REMOTE_REF))
// parameters.push(string(name: 'CITGM_LOGLEVEL', value: params.CITGM_LOGLEVEL))
buildJobs["$module@$module_version-$node_version($os $arch $distro)"] = { build(job: "MC-CITGM", parameters: parameters, propagate: false) }
}
def results = parallel(buildJobs)
def msg = '\nRESULTS:\n'
results.each { res ->
msg += "${res.key}: ${results[res.key].result}\n"
currentBuild.result = results[res.key].result
}
println msg
} }
stage('MC-License') { if (STARTFROM <= 3) {
/* Find missing licenses */
node ('linux && x64') {
checkout scm
withEnv(["HOST=${params.HOST}", "GIT_REMOTE_REF=${params.GIT_REMOTE_REF}"]) {
env.license_params = sh (
returnStdout: true,
script: "./missing-license.sh"
)
}
}
def license_params = env.license_params.trim().tokenize('%') // Create an array of parameters
// Create an array of buildJobs to run in parallel
def buildJobs = [:];
license_params.each { str ->
def p = str.tokenize(',')
def module = "${p[0].trim()}", module_version = "${p[1].trim()}"
def parameters = []
parameters.push(string(name: 'MODULE', value: module))
parameters.push(string(name: 'MODULE_VERSION', value: module_version))
parameters.push(string(name: 'NODE_VERSION', value: "8"))
parameters.push(string(name: 'HOST', value: params.HOST))
parameters.push(string(name: 'ENV', value: params.ENV))
parameters.push(string(name: 'GIT_REMOTE_REF', value: params.GIT_REMOTE_REF))
// parameters.push(string(name: 'CITGM_LOGLEVEL', value: params.CITGM_LOGLEVEL))
buildJobs["$module@$module_version"] = { build(job: "MC-License-Check", parameters: parameters, propagate: false) }
}
def results = parallel(buildJobs)
def msg = '\nRESULTS:\n'
results.each { res ->
msg += "${res.key}: ${results[res.key].result}\n"
currentBuild.result = results[res.key].result
}
println msg
} }
stage('POST-CLEANUP') { if (STARTFROM <= 4) {
node ('linux && x64') {
checkout scm
withEnv(["HOST=${params.HOST}", "API_USERNAME=${env.API_USERNAME}", "PASSWORD=${env.PASSWORD}", "GIT_REMOTE_REF=${params.GIT_REMOTE_REF}"]){
env.citgm_parameters = sh (
script: "./clean-data.sh"
)
}
}
} }
println "\n\n \\(• ◡ •)/ Pipeline COMPLETE \\(• ◡ •)/\n\n"
}