| 1 | #!groovy |
| 2 | |
| 3 | def OS = '{{OS}}' |
| 4 | def RELEASES = {{RELEASES}} |
| 5 | def ARCHES = {{ARCHES}} |
| 6 | def IMAGE_TYPES = {{IMAGE_TYPES}} |
| 7 | def PROFILES = {{PROFILES}} |
| 8 | def c = [RELEASES, |
| 9 | ARCHES, |
| 10 | IMAGE_TYPES].combinations() |
| 11 | c.removeAll({ |
| 12 | (params.ARCH_FILTER != 'all' && it[1] != params.ARCH_FILTER) || |
| 13 | (params.IMAGE_TYPE_FILTER != 'all' && it[2] != params.IMAGE_TYPE_FILTER) || |
| 14 | (params.RELEASE_FILTER != 'all' && it[0] != params.RELEASE_FILTER) |
| 15 | }) |
| 16 | |
| 17 | // Skip i386 Vms |
| 18 | c.removeAll({ |
| 19 | it[1] == 'i386' && it[2] == 'vm' |
| 20 | }) |
| 21 | |
| 22 | def base_image_tasks = [:] |
| 23 | def profile_image_tasks = [:] |
| 24 | for(int index = 0; index < c.size(); index++) { |
| 25 | def envMap = [ |
| 26 | RELEASE: c[index][0], |
| 27 | ARCH: c[index][1], |
| 28 | IMAGE_TYPE: c[index][2] |
| 29 | ] |
| 30 | def image_name = "${OS}/${envMap.RELEASE}/${envMap.ARCH}/${envMap.IMAGE_TYPE}" |
| 31 | base_image_tasks[image_name] = { -> |
| 32 | def job_ids = [] |
| 33 | stage("base:${image_name}") { |
| 34 | print(envMap) |
| 35 | build( |
| 36 | job: 'images_distrobuilder', |
| 37 | parameters: [ |
| 38 | string(name: 'OS', value: OS), |
| 39 | string(name: 'RELEASE', value: envMap.RELEASE), |
| 40 | string(name: 'ARCH', value: envMap.ARCH), |
| 41 | string(name: 'IMAGE_TYPE', value: envMap.IMAGE_TYPE), |
| 42 | string(name: 'GIT_URL', value: params.GIT_URL), |
| 43 | string(name: 'GIT_BRANCH', value: params.GIT_BRANCH) |
| 44 | ] |
| 45 | ) |
| 46 | } |
| 47 | } |
| 48 | for (int profile_index = 0; profile_index < PROFILES.size(); profile_index++) { |
| 49 | // Using a second map gets around some weirdness with the closures finding |
| 50 | // PROFILES[profile_index] where most jobs would have a null value for the |
| 51 | // profile |
| 52 | def envMap2 = envMap.clone() |
| 53 | envMap2.PROFILE = PROFILES[profile_index] |
| 54 | if (env.PROFILE_FILTER == 'all' || env.PROFILE_FILTER == PROFILES[profile_index]) { |
| 55 | profile_image_tasks["${PROFILES[profile_index]}:${image_name}"] = { -> |
| 56 | print(envMap2) |
| 57 | build( |
| 58 | job: 'images_imagebuilder', |
| 59 | parameters: [ |
| 60 | string(name: 'OS', value: OS), |
| 61 | string(name: 'RELEASE', value: envMap2.RELEASE), |
| 62 | string(name: 'ARCH', value: envMap2.ARCH), |
| 63 | string(name: 'IMAGE_TYPE', value: envMap2.IMAGE_TYPE), |
| 64 | string(name: 'PROFILE', value: envMap2.PROFILE), |
| 65 | string(name: 'GIT_URL', value: params.GIT_URL), |
| 66 | string(name: 'GIT_BRANCH', value: params.GIT_BRANCH) |
| 67 | ] |
| 68 | ) |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if (!params.SKIP_BASE_IMAGES) { |
| 75 | stage("base images") { |
| 76 | parallel(base_image_tasks) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if (!params.SKIP_PROFILE_IMAGES) { |
| 81 | // While it's possible to have the tasks in "base images" start |
| 82 | // their respective profile images_imagebuilder steps, it ends |
| 83 | // up creating a pipeline overview and log that is difficult to |
| 84 | // read in the Jenkins interface. |
| 85 | stage("profile images") { |
| 86 | parallel(profile_image_tasks) |
| 87 | } |
| 88 | } |