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 artifactory_server_id = 'artifactory-osm'
20 def get_archive(mdg, branch, build_name, build_number, pattern='*') {
21 server = Artifactory.server artifactory_server_id
23 println("retrieve archive for ${mdg}/${branch}/${build_name}/${build_number}/${pattern}")
25 def repo_prefix = 'osm-'
26 def downloadSpec = """{
30 "pattern": "${repo_prefix}${mdg}/${pattern}",
31 "build": "${build_name}/${build_number}"
36 server.download(downloadSpec)
37 // workaround. flatten and repo the specific build num from the directory
38 sh "cp -R ${build_num}/* ."
39 sh "rm -rf ${build_num}"
42 def get_env_value(build_env_file,key) {
43 return sh(returnStdout:true, script: "cat ${build_env_file} | awk -F= '/${key}/{print \$2}'").trim()
46 def lxc_run(container_name,cmd) {
47 return sh(returnStdout: true, script: "lxc exec ${container_name} -- ${cmd}").trim()
50 // start a http server
51 // return the http server URL
52 def start_http_server(repo_dir,server_name) {
53 sh "docker run -dit --name ${server_name} -v ${repo_dir}:/usr/local/apache2/htdocs/ httpd:2.4"
54 def http_server_ip = sh(returnStdout:true, script: "docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${server_name}").trim()
55 return "-u http://${http_server_ip}/"
58 def lxc_get_file(container_name,file,destination) {
59 sh "lxc file pull ${container_name}/${file} ${destination}"
62 def systest_run(container_name, test) {
63 // need to get the SO IP inside the running container
64 so_ip = lxc_run(container_name,"lxc list SO-ub -c 4|grep eth0 |awk '{print \$2}'")
65 //container_ip = get_ip_from_container(container_name)
67 lxc_run(container_name, "make -C devops/systest OSM_HOSTNAME=${so_ip} ${test}")
68 lxc_get_file(container_name, "/root/devops/systest/reports/pytest-${test}.xml",'.')
71 def get_ip_from_container( container_name ) {
72 return sh(returnStdout: true, script: "lxc list ${container_name} -c 4|grep eth0 |awk '{print \$2}'").trim()
75 def archive(mdg,branch,status) {
76 server = Artifactory.server artifactory_server_id
78 def properties = "branch=${branch};status=${status}"
79 def repo_prefix = 'osm-'
83 "pattern": "dists/*.gz",
84 "target": "${repo_prefix}${mdg}/${BUILD_NUMBER}/",
85 "props": "${properties}",
89 "pattern": "dists/*Packages",
90 "target": "${repo_prefix}${mdg}/${BUILD_NUMBER}/",
91 "props": "${properties}",
95 "pattern": "pool/*/*.deb",
96 "target": "${repo_prefix}${mdg}/${BUILD_NUMBER}/",
97 "props": "${properties}",
102 buildInfo = server.upload(uploadSpec)
103 //buildInfo.retention maxBuilds: 4
104 //buildInfo.retention deleteBuildArtifacts: false
106 server.publishBuildInfo(buildInfo)
108 // store the build environment into the jenkins artifact storage
110 archiveArtifacts artifacts: "build.env", fingerprint: true
114 //CANNOT use build promotion with OSS version of artifactory
115 // For now, will publish downloaded artifacts into a new repo.
116 def promote_build(mdg,branch,buildInfo) {
117 println("Promoting build: mdg: ${mdg} branch: ${branch} build: ${buildInfo.name}/${buildInfo.number}")
119 server = Artifactory.server artifactory_server_id
121 //def properties = "branch=${branch};status=${status}"
122 def repo_prefix = 'osm-'
123 def build_name = "${mdg}-stage_2 :: ${branch}"
125 def promotionConfig = [
126 // Mandatory parameters
127 "buildName" : buildInfo.name,
128 "buildNumber" : buildInfo.number,
129 'targetRepo' : 'osm-release',
131 // Optional parameters
132 'comment' : 'this is the promotion comment',
133 'sourceRepo' : "${repo_prefix}${mdg}",
134 'status' : 'Testing',
135 'includeDependencies': true,
137 // 'failFast' is true by default.
138 // Set it to false, if you don't want the promotion to abort upon receiving the first error.
142 server.promote promotionConfig
145 def get_mdg_from_project(project) {
146 // split the project.
147 def values = project.split('/')
148 if ( values.size() > 1 ) {
151 // no prefix, likely just the project name then