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 // if the build name does not contain merge, then this is a patchset/staging job
24 if (!build_name.contains('merge')) {
27 def repo_prefix = 'osm-'
28 def downloadSpec = """{
32 "pattern": "${repo_prefix}${mdg}/${branch}/${build_number}/${pattern}"
37 println("Searching Artifactory with ${downloadSpec}")
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)
48 // workaround. flatten repo to remove specific build num from the directory
49 sh "cp -R ${branch}/${build_number}/* ."
50 sh "rm -rf ${branch}/${build_number}"
52 return debian_packages
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()
59 def lxc_run(container_name,cmd) {
60 return sh(returnStdout: true, script: "lxc exec ${container_name} -- ${cmd}").trim()
63 def lxc_file_push(container_name,file,destination) {
64 return sh(returnStdout: true, script: "lxc file push ${file} ${container_name}/${destination}").trim()
67 // start a http server
68 // return the http server URL
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"
71 def http_server_ip = sh(returnStdout:true, script: "docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${server_name}").trim()
72 return "http://${http_server_ip}:${port}/"
75 def check_status_http_server(ip, port) {
77 timeout(time: 1, unit: 'MINUTES') {
81 script: "wget http://${ip}:${port}/release/dists/unstable/Release")
84 sleep(time: 5, unit: 'SECONDS')
88 println('HTTP server is ready and accepting http connections')
92 def lxc_get_file(container_name,file,destination) {
93 sh "lxc file pull ${container_name}/${file} ${destination}"
96 def systest_run(container_name, test, source_rc = null) {
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}'")
99 ro_ip = lxc_run(container_name,"lxc list RO -c 4|grep eth0 |awk '{print \$2}'")
100 //container_ip = get_ip_from_container(container_name)
103 pre_source = "/tmp/" + source_rc.substring(source_rc.lastIndexOf('/')+1)
105 lxc_file_push(container_name,source_rc,pre_source)
106 result = lxc_run(container_name, "sh -c '. ${pre_source}; make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}'")
111 result = lxc_run(container_name, "make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}")
114 lxc_get_file(container_name, "/root/devops/systest/reports/pytest-${test}.xml",'.')
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()
121 def archive(artifactory_server,mdg,branch,status) {
122 server = Artifactory.server artifactory_server
125 //def properties = "branch=${branch};status=${status}"
126 def repo_prefix = 'osm-'
128 // if the build name does not contain merge, then this is a patchset/staging job
129 if ( !JOB_NAME.contains('merge') ) {
132 def uploadSpec = """{
135 "pattern": "dists/*.gz",
136 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
137 "props": "${properties}",
141 "pattern": "dists/*Packages",
142 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
143 "props": "${properties}",
147 "pattern": "pool/*/*.deb",
148 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
149 "props": "${properties}",
153 "pattern": "changelog/*",
154 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
155 "props": "${properties}",
160 buildInfo = server.upload(uploadSpec)
161 //buildInfo.retention maxBuilds: 4
162 //buildInfo.retention deleteBuildArtifacts: false
164 server.publishBuildInfo(buildInfo)
166 // store the build environment into the jenkins artifact storage
168 archiveArtifacts artifacts: "build.env", fingerprint: true
172 //CANNOT use build promotion with OSS version of artifactory
173 // For now, will publish downloaded artifacts into a new repo.
174 def promote_build(artifactory_server,mdg,branch,buildInfo) {
175 println("Promoting build: mdg: ${mdg} branch: ${branch} build: ${buildInfo.name}/${buildInfo.number}")
177 server = Artifactory.server artifactory_server
179 //def properties = "branch=${branch};status=${status}"
180 def repo_prefix = 'osm-'
181 def build_name = "${mdg}-stage_2 :: ${branch}"
183 def promotionConfig = [
184 // Mandatory parameters
185 "buildName" : buildInfo.name,
186 "buildNumber" : buildInfo.number,
187 'targetRepo' : 'osm-release',
189 // Optional parameters
190 'comment' : 'this is the promotion comment',
191 'sourceRepo' : "${repo_prefix}${mdg}",
192 'status' : 'Testing',
193 'includeDependencies': true,
195 // 'failFast' is true by default.
196 // Set it to false, if you don't want the promotion to abort upon receiving the first error.
200 server.promote promotionConfig
203 def get_mdg_from_project(project) {
204 // split the project.
205 def values = project.split('/')
206 if ( values.size() > 1 ) {
209 // no prefix, likely just the project name then