| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 1 | /* Copyright 2017 Sandvine |
| 2 | * |
| 3 | * All Rights Reserved. |
| David Garcia | a60ec73 | 2021-03-17 15:28:47 +0100 | [diff] [blame] | 4 | * |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | * not use this file except in compliance with the License. You may obtain |
| 7 | * a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | * License for the specific language governing permissions and limitations |
| 15 | * under the License. |
| 16 | */ |
| 17 | |
| Wesley Hirsch | 92da206 | 2017-09-08 17:42:29 -0400 | [diff] [blame] | 18 | def get_archive(artifactory_server, mdg, branch, build_name, build_number, pattern='*') { |
| 19 | server = Artifactory.server artifactory_server |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 20 | |
| 21 | println("retrieve archive for ${mdg}/${branch}/${build_name}/${build_number}/${pattern}") |
| 22 | |
| Mike Marchetti | 4ffe5fe | 2017-11-21 15:07:59 -0500 | [diff] [blame] | 23 | // if the build name does not contain merge, then this is a patchset/staging job |
| 24 | if (!build_name.contains('merge')) { |
| 25 | branch += '-staging' |
| 26 | } |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 27 | def repo_prefix = 'osm-' |
| 28 | def downloadSpec = """{ |
| 29 | "files": [ |
| 30 | { |
| 31 | "target": "./", |
| beierlm | 499b442 | 2022-02-04 11:14:33 -0500 | [diff] [blame] | 32 | "pattern": "${repo_prefix}${mdg}/${branch}/${build_number}/${pattern}" |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 33 | } |
| 34 | ] |
| 35 | }""" |
| 36 | |
| beierlm | 499b442 | 2022-02-04 11:14:33 -0500 | [diff] [blame] | 37 | println("Searching Artifactory with ${downloadSpec}") |
| 38 | |
| David Garcia | a60ec73 | 2021-03-17 15:28:47 +0100 | [diff] [blame] | 39 | def results = server.download(downloadSpec) |
| 40 | // Save the list of URLs that we need to pass to the dockerfiles for build |
| 41 | def debian_packages = [] |
| 42 | for ( result in results.getDependencies()) { |
| 43 | if (result.remotePath.contains(".deb")) { |
| 44 | debian_packages.add(result.remotePath) |
| 45 | } |
| 46 | } |
| 47 | |
| Mike Marchetti | 4ffe5fe | 2017-11-21 15:07:59 -0500 | [diff] [blame] | 48 | // workaround. flatten repo to remove specific build num from the directory |
| David Garcia | a60ec73 | 2021-03-17 15:28:47 +0100 | [diff] [blame] | 49 | sh "cp -R ${branch}/${build_number}/* ." |
| 50 | sh "rm -rf ${branch}/${build_number}" |
| 51 | |
| 52 | return debian_packages |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | def get_env_value(build_env_file,key) { |
| 56 | return sh(returnStdout:true, script: "cat ${build_env_file} | awk -F= '/${key}/{print \$2}'").trim() |
| 57 | } |
| 58 | |
| 59 | def lxc_run(container_name,cmd) { |
| 60 | return sh(returnStdout: true, script: "lxc exec ${container_name} -- ${cmd}").trim() |
| 61 | } |
| 62 | |
| Mike Marchetti | f94dd8a | 2017-11-06 11:04:38 -0500 | [diff] [blame] | 63 | def lxc_file_push(container_name,file,destination) { |
| 64 | return sh(returnStdout: true, script: "lxc file push ${file} ${container_name}/${destination}").trim() |
| 65 | } |
| 66 | |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 67 | // start a http server |
| 68 | // return the http server URL |
| beierlm | 7b0acc0 | 2020-11-19 11:39:36 -0500 | [diff] [blame] | 69 | def start_http_server(repo_dir,server_name,port) { |
| 70 | sh "docker run -dit --name ${server_name} -p ${port}:80 -v ${repo_dir}:/usr/local/apache2/htdocs/ httpd:2.4" |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 71 | def http_server_ip = sh(returnStdout:true, script: "docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${server_name}").trim() |
| garciadeblas | 7db714f | 2022-04-22 12:05:15 +0200 | [diff] [blame] | 72 | return "http://${http_server_ip}:${port}/" |
| 73 | } |
| 74 | |
| 75 | def check_status_http_server(ip, port) { |
| 76 | alive = false |
| 77 | timeout(time: 1, unit: 'MINUTES') { |
| 78 | while (!alive) { |
| 79 | output = sh( |
| 80 | returnStatus: true, |
| 81 | script: "wget http://${ip}:${port}/release/dists/unstable/Release") |
| 82 | alive = (output == 0) |
| 83 | if (!alive) { |
| 84 | sleep(time: 5, unit: 'SECONDS') |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | println('HTTP server is ready and accepting http connections') |
| 89 | return |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | def lxc_get_file(container_name,file,destination) { |
| 93 | sh "lxc file pull ${container_name}/${file} ${destination}" |
| 94 | } |
| 95 | |
| Mike Marchetti | f94dd8a | 2017-11-06 11:04:38 -0500 | [diff] [blame] | 96 | def systest_run(container_name, test, source_rc = null) { |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 97 | // need to get the SO IP inside the running container |
| 98 | so_ip = lxc_run(container_name,"lxc list SO-ub -c 4|grep eth0 |awk '{print \$2}'") |
| Mike Marchetti | f94dd8a | 2017-11-06 11:04:38 -0500 | [diff] [blame] | 99 | ro_ip = lxc_run(container_name,"lxc list RO -c 4|grep eth0 |awk '{print \$2}'") |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 100 | //container_ip = get_ip_from_container(container_name) |
| David Garcia | a60ec73 | 2021-03-17 15:28:47 +0100 | [diff] [blame] | 101 | |
| Mike Marchetti | f94dd8a | 2017-11-06 11:04:38 -0500 | [diff] [blame] | 102 | if ( source_rc ) { |
| 103 | pre_source = "/tmp/" + source_rc.substring(source_rc.lastIndexOf('/')+1) |
| David Garcia | a60ec73 | 2021-03-17 15:28:47 +0100 | [diff] [blame] | 104 | |
| Mike Marchetti | f94dd8a | 2017-11-06 11:04:38 -0500 | [diff] [blame] | 105 | lxc_file_push(container_name,source_rc,pre_source) |
| Mike Marchetti | 3433465 | 2018-05-04 10:26:42 -0400 | [diff] [blame] | 106 | result = lxc_run(container_name, "sh -c '. ${pre_source}; make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}'") |
| 107 | echo result |
| Mike Marchetti | f94dd8a | 2017-11-06 11:04:38 -0500 | [diff] [blame] | 108 | } |
| 109 | else |
| 110 | { |
| Mike Marchetti | 34b892a | 2018-04-16 13:57:12 -0400 | [diff] [blame] | 111 | result = lxc_run(container_name, "make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}") |
| 112 | echo result |
| Mike Marchetti | f94dd8a | 2017-11-06 11:04:38 -0500 | [diff] [blame] | 113 | } |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 114 | lxc_get_file(container_name, "/root/devops/systest/reports/pytest-${test}.xml",'.') |
| 115 | } |
| 116 | |
| 117 | def get_ip_from_container( container_name ) { |
| 118 | return sh(returnStdout: true, script: "lxc list ${container_name} -c 4|grep eth0 |awk '{print \$2}'").trim() |
| 119 | } |
| 120 | |
| Wesley Hirsch | 92da206 | 2017-09-08 17:42:29 -0400 | [diff] [blame] | 121 | def archive(artifactory_server,mdg,branch,status) { |
| 122 | server = Artifactory.server artifactory_server |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 123 | |
| Mike Marchetti | 4ffe5fe | 2017-11-21 15:07:59 -0500 | [diff] [blame] | 124 | def properties = "" |
| 125 | //def properties = "branch=${branch};status=${status}" |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 126 | def repo_prefix = 'osm-' |
| Mike Marchetti | 4ffe5fe | 2017-11-21 15:07:59 -0500 | [diff] [blame] | 127 | |
| 128 | // if the build name does not contain merge, then this is a patchset/staging job |
| 129 | if ( !JOB_NAME.contains('merge') ) { |
| 130 | branch += '-staging' |
| 131 | } |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 132 | def uploadSpec = """{ |
| 133 | "files": [ |
| 134 | { |
| Mark Beierl | 473c541 | 2023-04-03 13:32:22 -0400 | [diff] [blame] | 135 | "pattern": "dists/*.gz", |
| 136 | "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/", |
| 137 | "props": "${properties}", |
| 138 | "flat": false |
| 139 | }, |
| 140 | { |
| 141 | "pattern": "dists/*Packages", |
| 142 | "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/", |
| 143 | "props": "${properties}", |
| 144 | "flat": false |
| 145 | }, |
| 146 | { |
| garciadeblas | 740e877 | 2023-02-28 12:56:07 +0100 | [diff] [blame] | 147 | "pattern": "dist/*.whl", |
| Mike Marchetti | b8e4473 | 2017-09-12 10:36:02 -0400 | [diff] [blame] | 148 | "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/", |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 149 | "props": "${properties}", |
| 150 | "flat": false |
| 151 | }, |
| 152 | { |
| 153 | "pattern": "pool/*/*.deb", |
| Mike Marchetti | b8e4473 | 2017-09-12 10:36:02 -0400 | [diff] [blame] | 154 | "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/", |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 155 | "props": "${properties}", |
| 156 | "flat": false |
| Mike Marchetti | 4ffe5fe | 2017-11-21 15:07:59 -0500 | [diff] [blame] | 157 | }, |
| 158 | { |
| 159 | "pattern": "changelog/*", |
| 160 | "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/", |
| 161 | "props": "${properties}", |
| 162 | "flat": false |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 163 | }] |
| 164 | }""" |
| 165 | |
| 166 | buildInfo = server.upload(uploadSpec) |
| 167 | //buildInfo.retention maxBuilds: 4 |
| 168 | //buildInfo.retention deleteBuildArtifacts: false |
| 169 | |
| 170 | server.publishBuildInfo(buildInfo) |
| 171 | |
| 172 | // store the build environment into the jenkins artifact storage |
| 173 | sh 'env > build.env' |
| 174 | archiveArtifacts artifacts: "build.env", fingerprint: true |
| 175 | } |
| 176 | |
| 177 | |
| 178 | //CANNOT use build promotion with OSS version of artifactory |
| 179 | // For now, will publish downloaded artifacts into a new repo. |
| Wesley Hirsch | 92da206 | 2017-09-08 17:42:29 -0400 | [diff] [blame] | 180 | def promote_build(artifactory_server,mdg,branch,buildInfo) { |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 181 | println("Promoting build: mdg: ${mdg} branch: ${branch} build: ${buildInfo.name}/${buildInfo.number}") |
| 182 | |
| Wesley Hirsch | 92da206 | 2017-09-08 17:42:29 -0400 | [diff] [blame] | 183 | server = Artifactory.server artifactory_server |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 184 | |
| 185 | //def properties = "branch=${branch};status=${status}" |
| 186 | def repo_prefix = 'osm-' |
| 187 | def build_name = "${mdg}-stage_2 :: ${branch}" |
| 188 | |
| 189 | def promotionConfig = [ |
| 190 | // Mandatory parameters |
| 191 | "buildName" : buildInfo.name, |
| 192 | "buildNumber" : buildInfo.number, |
| 193 | 'targetRepo' : 'osm-release', |
| David Garcia | a60ec73 | 2021-03-17 15:28:47 +0100 | [diff] [blame] | 194 | |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 195 | // Optional parameters |
| 196 | 'comment' : 'this is the promotion comment', |
| 197 | 'sourceRepo' : "${repo_prefix}${mdg}", |
| 198 | 'status' : 'Testing', |
| 199 | 'includeDependencies': true, |
| 200 | 'copy' : true, |
| 201 | // 'failFast' is true by default. |
| 202 | // Set it to false, if you don't want the promotion to abort upon receiving the first error. |
| 203 | 'failFast' : true |
| 204 | ] |
| 205 | |
| 206 | server.promote promotionConfig |
| 207 | } |
| 208 | |
| 209 | def get_mdg_from_project(project) { |
| 210 | // split the project. |
| 211 | def values = project.split('/') |
| 212 | if ( values.size() > 1 ) { |
| 213 | return values[1] |
| 214 | } |
| 215 | // no prefix, likely just the project name then |
| 216 | return project |
| 217 | } |
| 218 | |
| 219 | |
| 220 | return this |