-
Notifications
You must be signed in to change notification settings - Fork 138
/
cloud-maintenance-gating.Jenkinsfile
128 lines (115 loc) · 4.43 KB
/
cloud-maintenance-gating.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
/**
* The openstack-maintenance-gating Jenkins Pipeline
*/
pipeline {
// skip the default checkout, because we want to use a custom path
options {
skipDefaultCheckout()
timestamps()
}
agent {
node {
label 'cloud-ci-trigger'
customWorkspace "${JOB_NAME}-${BUILD_NUMBER}"
}
}
stages {
stage('Setup workspace') {
steps {
script {
if (cloud_env == '') {
error("Empty 'cloud_env' parameter value.")
}
if (maint_updates == '') {
error("Empty 'maint_updates' parameter value.")
}
currentBuild.displayName = "#${BUILD_NUMBER}: ${maint_updates}"
sh('''
git clone $git_automation_repo --branch $git_automation_branch automation-git
''')
cloud_lib = load "$WORKSPACE/automation-git/jenkins/ci.suse.de/pipelines/openstack-cloud.groovy"
def muBuildUrlList = []
cloudversion = []
for (project in maint_updates.split(',')) {
muBuildUrlList = muBuildUrlList + "<a href='https://build.suse.de/project/show/SUSE:Maintenance:${project}'>${project}</a>"
cloudversions = cloud_lib.maintenance_status("-a get-versions -p ${project}")
if (cloudversions == '') {
def errorMsg = "ERROR: Could not find maintenance update: ${project}"
echo errorMsg
error(errorMsg)
}
cloudversion.addAll(cloudversions.split(':')[1].split(','))
}
cloudversion.unique()
currentBuild.description = "Maintenance Updates: " + muBuildUrlList.join(", ") + "<br>Products: " + cloudversion.join(", ")
for (project in maint_updates.split(',')) {
cloud_lib.maintenance_status("-a set-status -p ${project} -s running -m ${BUILD_URL}display/redirect")
}
cloud_lib.load_extra_params_as_vars(extra_params)
}
}
}
stage('Trigger jobs') {
// Do not abort all stages if one of them fails
failFast false
steps {
script {
def parallelJobMap = cloud_lib.generate_parallel_stages(
cloudversion,
job_filter.tokenize(','),
"$WORKSPACE/automation-git/jenkins/ci.suse.de/pipelines/cloud-maintenance-gating-config.yml") {
job_title, job_def ->
// reserve a resource here for the integration job, to avoid
// keeping a cloud-ci worker busy while waiting for a
// resource to become available.
cloud_lib.run_with_reserved_env(reserve_env.toBoolean(), cloud_env, "${cloud_env}-${job_title}") {
reserved_env ->
def job_params = [
cloud_env : reserved_env,
reserve_env : false,
maint_updates : maint_updates,
rc_notify : false,
cleanup : "on success",
git_automation_repo : git_automation_repo,
git_automation_branch: git_automation_branch
]
// override default parameters with those loaded from config file
job_params.putAll(job_def.job_params)
// combine together extra_params from this job with those loaded from config file
combined_extra_params = [extra_params, job_def.job_params.extra_params?: ""].join('\n').trim()
if (!combined_extra_params.isEmpty()) {
job_params.extra_params = combined_extra_params
}
cloud_lib.trigger_build(job_def.job_name, cloud_lib.convert_to_build_params(job_params))
}
}
if (parallelJobMap.isEmpty()) {
def errorMsg = "ERROR: No jobs found that matched the '${cloudversion}' cloud versions and the '${job_filter}' job filter."
echo errorMsg
error(errorMsg)
}
parallel parallelJobMap
}
}
}
}
post{
success {
script {
for (project in maint_updates.split(',')) {
cloud_lib.maintenance_status("-a set-status -p ${project} -s success -m ${BUILD_URL}display/redirect")
}
}
}
failure {
script {
for (project in maint_updates.split(',')) {
cloud_lib.maintenance_status("-a set-status -p ${project} -s failure -m ${BUILD_URL}display/redirect")
}
}
}
cleanup {
cleanWs()
}
}
}