1 /* Copyright 2017 Sandvine
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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
18 def get_archive(artifactory_server, mdg, branch, build_name, build_number, pattern='*') {
19 server = Artifactory.server artifactory_server
21 println("retrieve archive for ${mdg}/${branch}/${build_name}/${build_number}/${pattern}")
23 def repo_prefix = 'osm-'
24 def downloadSpec = """{
28 "pattern": "${repo_prefix}${mdg}/${branch}/${pattern}",
29 "build": "${build_name}/${build_number}"
34 server.download(downloadSpec)
35 // workaround. flatten and repo the specific build num from the directory
36 sh "cp -R ${branch}/${build_num}/* ."
37 sh "rm -rf ${branch}/${build_num}"
40 def get_env_value(build_env_file,key) {
41 return sh(returnStdout:true, script: "cat ${build_env_file} | awk -F= '/${key}/{print \$2}'").trim()
44 def lxc_run(container_name,cmd) {
45 return sh(returnStdout: true, script: "lxc exec ${container_name} -- ${cmd}").trim()
48 def lxc_file_push(container_name,file,destination) {
49 return sh(returnStdout: true, script: "lxc file push ${file} ${container_name}/${destination}").trim()
52 // start a http server
53 // return the http server URL
54 def start_http_server(repo_dir,server_name) {
55 sh "docker run -dit --name ${server_name} -v ${repo_dir}:/usr/local/apache2/htdocs/ httpd:2.4"
56 def http_server_ip = sh(returnStdout:true, script: "docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${server_name}").trim()
57 return "-u http://${http_server_ip}/"
60 def lxc_get_file(container_name,file,destination) {
61 sh "lxc file pull ${container_name}/${file} ${destination}"
64 def systest_run(container_name, test, source_rc = null) {
65 // need to get the SO IP inside the running container
66 so_ip = lxc_run(container_name,"lxc list SO-ub -c 4|grep eth0 |awk '{print \$2}'")
67 ro_ip = lxc_run(container_name,"lxc list RO -c 4|grep eth0 |awk '{print \$2}'")
68 //container_ip = get_ip_from_container(container_name)
71 pre_source = "/tmp/" + source_rc.substring(source_rc.lastIndexOf('/')+1)
73 lxc_file_push(container_name,source_rc,pre_source)
74 lxc_run(container_name, "sh -c '. ${pre_source}; make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}'")
78 lxc_run(container_name, "make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}")
80 lxc_get_file(container_name, "/root/devops/systest/reports/pytest-${test}.xml",'.')
83 def get_ip_from_container( container_name ) {
84 return sh(returnStdout: true, script: "lxc list ${container_name} -c 4|grep eth0 |awk '{print \$2}'").trim()
87 def archive(artifactory_server,mdg,branch,status) {
88 server = Artifactory.server artifactory_server
90 def properties = "branch=${branch};status=${status}"
91 def repo_prefix = 'osm-'
95 "pattern": "dists/*.gz",
96 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
97 "props": "${properties}",
101 "pattern": "dists/*Packages",
102 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
103 "props": "${properties}",
107 "pattern": "pool/*/*.deb",
108 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
109 "props": "${properties}",
114 buildInfo = server.upload(uploadSpec)
115 //buildInfo.retention maxBuilds: 4
116 //buildInfo.retention deleteBuildArtifacts: false
118 server.publishBuildInfo(buildInfo)
120 // store the build environment into the jenkins artifact storage
122 archiveArtifacts artifacts: "build.env", fingerprint: true
126 //CANNOT use build promotion with OSS version of artifactory
127 // For now, will publish downloaded artifacts into a new repo.
128 def promote_build(artifactory_server,mdg,branch,buildInfo) {
129 println("Promoting build: mdg: ${mdg} branch: ${branch} build: ${buildInfo.name}/${buildInfo.number}")
131 server = Artifactory.server artifactory_server
133 //def properties = "branch=${branch};status=${status}"
134 def repo_prefix = 'osm-'
135 def build_name = "${mdg}-stage_2 :: ${branch}"
137 def promotionConfig = [
138 // Mandatory parameters
139 "buildName" : buildInfo.name,
140 "buildNumber" : buildInfo.number,
141 'targetRepo' : 'osm-release',
143 // Optional parameters
144 'comment' : 'this is the promotion comment',
145 'sourceRepo' : "${repo_prefix}${mdg}",
146 'status' : 'Testing',
147 'includeDependencies': true,
149 // 'failFast' is true by default.
150 // Set it to false, if you don't want the promotion to abort upon receiving the first error.
154 server.promote promotionConfig
157 def get_mdg_from_project(project) {
158 // split the project.
159 def values = project.split('/')
160 if ( values.size() > 1 ) {
163 // no prefix, likely just the project name then