| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 1 | /* Copyright 2017 Sandvine |
| 2 | * |
| 3 | * All Rights Reserved. |
| 4 | * |
| 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": "./", |
| Mike Marchetti | 4ffe5fe | 2017-11-21 15:07:59 -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 | "build": "${build_name}/${build_number}" |
| 34 | } |
| 35 | ] |
| 36 | }""" |
| 37 | |
| 38 | server.download(downloadSpec) |
| Mike Marchetti | 4ffe5fe | 2017-11-21 15:07:59 -0500 | [diff] [blame] | 39 | // workaround. flatten repo to remove specific build num from the directory |
| Mike Marchetti | ea319bf | 2017-09-20 15:58:32 -0400 | [diff] [blame] | 40 | sh "cp -R ${branch}/${build_num}/* ." |
| 41 | sh "rm -rf ${branch}/${build_num}" |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | def get_env_value(build_env_file,key) { |
| 45 | return sh(returnStdout:true, script: "cat ${build_env_file} | awk -F= '/${key}/{print \$2}'").trim() |
| 46 | } |
| 47 | |
| 48 | def lxc_run(container_name,cmd) { |
| 49 | return sh(returnStdout: true, script: "lxc exec ${container_name} -- ${cmd}").trim() |
| 50 | } |
| 51 | |
| Mike Marchetti | f94dd8a | 2017-11-06 11:04:38 -0500 | [diff] [blame] | 52 | def lxc_file_push(container_name,file,destination) { |
| 53 | return sh(returnStdout: true, script: "lxc file push ${file} ${container_name}/${destination}").trim() |
| 54 | } |
| 55 | |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 56 | // start a http server |
| 57 | // return the http server URL |
| 58 | def start_http_server(repo_dir,server_name) { |
| 59 | sh "docker run -dit --name ${server_name} -v ${repo_dir}:/usr/local/apache2/htdocs/ httpd:2.4" |
| 60 | def http_server_ip = sh(returnStdout:true, script: "docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${server_name}").trim() |
| 61 | return "-u http://${http_server_ip}/" |
| 62 | } |
| 63 | |
| 64 | def lxc_get_file(container_name,file,destination) { |
| 65 | sh "lxc file pull ${container_name}/${file} ${destination}" |
| 66 | } |
| 67 | |
| Mike Marchetti | f94dd8a | 2017-11-06 11:04:38 -0500 | [diff] [blame] | 68 | def systest_run(container_name, test, source_rc = null) { |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 69 | // need to get the SO IP inside the running container |
| 70 | 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] | 71 | 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] | 72 | //container_ip = get_ip_from_container(container_name) |
| Mike Marchetti | f94dd8a | 2017-11-06 11:04:38 -0500 | [diff] [blame] | 73 | |
| 74 | if ( source_rc ) { |
| 75 | pre_source = "/tmp/" + source_rc.substring(source_rc.lastIndexOf('/')+1) |
| 76 | |
| 77 | lxc_file_push(container_name,source_rc,pre_source) |
| 78 | lxc_run(container_name, "sh -c '. ${pre_source}; make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}'") |
| 79 | } |
| 80 | else |
| 81 | { |
| Mike Marchetti | 34b892a | 2018-04-16 13:57:12 -0400 | [diff] [blame] | 82 | result = lxc_run(container_name, "make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}") |
| 83 | echo result |
| Mike Marchetti | f94dd8a | 2017-11-06 11:04:38 -0500 | [diff] [blame] | 84 | } |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 85 | lxc_get_file(container_name, "/root/devops/systest/reports/pytest-${test}.xml",'.') |
| 86 | } |
| 87 | |
| 88 | def get_ip_from_container( container_name ) { |
| 89 | return sh(returnStdout: true, script: "lxc list ${container_name} -c 4|grep eth0 |awk '{print \$2}'").trim() |
| 90 | } |
| 91 | |
| Wesley Hirsch | 92da206 | 2017-09-08 17:42:29 -0400 | [diff] [blame] | 92 | def archive(artifactory_server,mdg,branch,status) { |
| 93 | server = Artifactory.server artifactory_server |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 94 | |
| Mike Marchetti | 4ffe5fe | 2017-11-21 15:07:59 -0500 | [diff] [blame] | 95 | def properties = "" |
| 96 | //def properties = "branch=${branch};status=${status}" |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 97 | def repo_prefix = 'osm-' |
| Mike Marchetti | 4ffe5fe | 2017-11-21 15:07:59 -0500 | [diff] [blame] | 98 | |
| 99 | // if the build name does not contain merge, then this is a patchset/staging job |
| 100 | if ( !JOB_NAME.contains('merge') ) { |
| 101 | branch += '-staging' |
| 102 | } |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 103 | def uploadSpec = """{ |
| 104 | "files": [ |
| 105 | { |
| 106 | "pattern": "dists/*.gz", |
| Mike Marchetti | b8e4473 | 2017-09-12 10:36:02 -0400 | [diff] [blame] | 107 | "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/", |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 108 | "props": "${properties}", |
| 109 | "flat": false |
| 110 | }, |
| 111 | { |
| 112 | "pattern": "dists/*Packages", |
| Mike Marchetti | b8e4473 | 2017-09-12 10:36:02 -0400 | [diff] [blame] | 113 | "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/", |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 114 | "props": "${properties}", |
| 115 | "flat": false |
| 116 | }, |
| 117 | { |
| 118 | "pattern": "pool/*/*.deb", |
| Mike Marchetti | b8e4473 | 2017-09-12 10:36:02 -0400 | [diff] [blame] | 119 | "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/", |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 120 | "props": "${properties}", |
| 121 | "flat": false |
| Mike Marchetti | 4ffe5fe | 2017-11-21 15:07:59 -0500 | [diff] [blame] | 122 | }, |
| 123 | { |
| 124 | "pattern": "changelog/*", |
| 125 | "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/", |
| 126 | "props": "${properties}", |
| 127 | "flat": false |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 128 | }] |
| 129 | }""" |
| 130 | |
| 131 | buildInfo = server.upload(uploadSpec) |
| 132 | //buildInfo.retention maxBuilds: 4 |
| 133 | //buildInfo.retention deleteBuildArtifacts: false |
| 134 | |
| 135 | server.publishBuildInfo(buildInfo) |
| 136 | |
| 137 | // store the build environment into the jenkins artifact storage |
| 138 | sh 'env > build.env' |
| 139 | archiveArtifacts artifacts: "build.env", fingerprint: true |
| 140 | } |
| 141 | |
| 142 | |
| 143 | //CANNOT use build promotion with OSS version of artifactory |
| 144 | // For now, will publish downloaded artifacts into a new repo. |
| Wesley Hirsch | 92da206 | 2017-09-08 17:42:29 -0400 | [diff] [blame] | 145 | def promote_build(artifactory_server,mdg,branch,buildInfo) { |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 146 | println("Promoting build: mdg: ${mdg} branch: ${branch} build: ${buildInfo.name}/${buildInfo.number}") |
| 147 | |
| Wesley Hirsch | 92da206 | 2017-09-08 17:42:29 -0400 | [diff] [blame] | 148 | server = Artifactory.server artifactory_server |
| Mike Marchetti | 8343e3f | 2017-06-30 15:12:26 -0400 | [diff] [blame] | 149 | |
| 150 | //def properties = "branch=${branch};status=${status}" |
| 151 | def repo_prefix = 'osm-' |
| 152 | def build_name = "${mdg}-stage_2 :: ${branch}" |
| 153 | |
| 154 | def promotionConfig = [ |
| 155 | // Mandatory parameters |
| 156 | "buildName" : buildInfo.name, |
| 157 | "buildNumber" : buildInfo.number, |
| 158 | 'targetRepo' : 'osm-release', |
| 159 | |
| 160 | // Optional parameters |
| 161 | 'comment' : 'this is the promotion comment', |
| 162 | 'sourceRepo' : "${repo_prefix}${mdg}", |
| 163 | 'status' : 'Testing', |
| 164 | 'includeDependencies': true, |
| 165 | 'copy' : true, |
| 166 | // 'failFast' is true by default. |
| 167 | // Set it to false, if you don't want the promotion to abort upon receiving the first error. |
| 168 | 'failFast' : true |
| 169 | ] |
| 170 | |
| 171 | server.promote promotionConfig |
| 172 | } |
| 173 | |
| 174 | def get_mdg_from_project(project) { |
| 175 | // split the project. |
| 176 | def values = project.split('/') |
| 177 | if ( values.size() > 1 ) { |
| 178 | return values[1] |
| 179 | } |
| 180 | // no prefix, likely just the project name then |
| 181 | return project |
| 182 | } |
| 183 | |
| 184 | |
| 185 | return this |