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
20 string(defaultValue: env.GERRIT_BRANCH, description: '', name: 'GERRIT_BRANCH'),
21 string(defaultValue: 'system', description: '', name: 'NODE'),
22 string(defaultValue: '', description: '', name: 'BUILD_FROM_SOURCE'),
23 string(defaultValue: 'unstable', description: '', name: 'REPO_DISTRO'),
24 string(defaultValue: '', description: '', name: 'COMMIT_ID'),
25 string(defaultValue: '-stage_2', description: '', name: 'UPSTREAM_SUFFIX'),
26 string(defaultValue: 'pubkey.asc', description: '', name: 'REPO_KEY_NAME'),
27 string(defaultValue: 'release', description: '', name: 'RELEASE'),
28 string(defaultValue: '', description: '', name: 'UPSTREAM_JOB_NAME'),
29 string(defaultValue: '', description: '', name: 'UPSTREAM_JOB_NUMBER'),
30 string(defaultValue: '', description: '', name: 'UPSTREAM_JOB_NUMBER'),
31 string(defaultValue: 'dpkg1', description: '', name: 'GPG_KEY_NAME'),
32 string(defaultValue: 'artifactory-osm', description: '', name: 'ARTIFACTORY_SERVER'),
33 string(defaultValue: 'osm-stage_4', description: '', name: 'DOWNSTREAM_STAGE_NAME'),
34 string(defaultValue: 'releasefive-daily', description: '', name: 'DOCKER_TAG'),
35 booleanParam(defaultValue: false, description: '', name: 'SAVE_CONTAINER_ON_FAIL'),
36 booleanParam(defaultValue: false, description: '', name: 'SAVE_CONTAINER_ON_PASS'),
37 booleanParam(defaultValue: true, description: '', name: 'SAVE_ARTIFACTS_ON_SMOKE_SUCCESS'),
38 booleanParam(defaultValue: false, description: '', name: 'DO_STAGE_4'),
39 booleanParam(defaultValue: true, description: '', name: 'DO_BUILD'),
40 booleanParam(defaultValue: true, description: '', name: 'DO_INSTALL'),
41 booleanParam(defaultValue: true, description: '', name: 'DO_SMOKE'),
42 booleanParam(defaultValue: true, description: '', name: 'DO_DOCKERPUSH'),
43 booleanParam(defaultValue: false, description: '', name: 'SAVE_ARTIFACTS_OVERRIDE'),
44 string(defaultValue: '/home/jenkins/hive/openstack-whitestack.rc', description: '', name: 'HIVE_VIM_1'),
48 def uninstall_osm(stackName) {
50 export OSM_USE_LOCAL_DEVOPS=true
51 export PATH=$PATH:/snap/bin
52 installers/full_install_osm.sh -y -w /tmp/osm -t ${stackName} -s ${stackName} --test --nolxd --nodocker --nojuju --nohostports --nohostclient --uninstall
56 def run_systest(stackName,tagName,testName,envfile=null) {
57 tempdir = sh(returnStdout: true, script: "mktemp -d").trim()
60 sh(script: "touch ${tempdir}/env")
61 envfile="${tempdir}/env"
63 sh "docker run --network net${stackName} --env-file ${envfile} -v ${tempdir}:/usr/share/osm-devops/systest/reports osm/osmclient:${tagName} make -C /usr/share/osm-devops/systest ${testName}"
64 sh "cp ${tempdir}/* ."
68 node("${params.NODE}") {
72 tag_or_branch = params.GERRIT_BRANCH.replaceAll(/\./,"")
78 ci_helper = load "jenkins/ci-pipelines/ci_helper.groovy"
80 def upstream_main_job = params.UPSTREAM_SUFFIX
82 // upstream jobs always use merged artifacts
83 upstream_main_job += '-merge'
84 container_name_prefix = "osm-${tag_or_branch}"
85 container_name = "${container_name_prefix}"
87 keep_artifacts = false
88 if ( JOB_NAME.contains('merge') ) {
89 container_name += "-merge"
91 // On a merge job, we keep artifacts on smoke success
92 keep_artifacts = params.SAVE_ARTIFACTS_ON_SMOKE_SUCCESS
94 container_name += "-${BUILD_NUMBER}"
96 // Copy the artifacts from the upstream jobs
97 stage("Copy Artifacts") {
98 // cleanup any previous repo
101 // grab all stable upstream builds based on the
104 def list = ["RO", "openvim", "osmclient", "IM", "devops", "MON", "N2VC", "NBI", "common", "LCM", "POL"]
105 for (component in list) {
106 step ([$class: 'CopyArtifact',
107 projectName: "${component}${upstream_main_job}/${GERRIT_BRANCH}"])
109 // grab the build name/number
110 //options = get_env_from_build('build.env')
111 build_num = ci_helper.get_env_value('build.env','BUILD_NUMBER')
113 // grab the archives from the stage_2 builds (ie. this will be the artifacts stored based on a merge)
114 ci_helper.get_archive(params.ARTIFACTORY_SERVER,component,GERRIT_BRANCH, "${component}${upstream_main_job} :: ${GERRIT_BRANCH}", build_num)
116 // cleanup any prevously defined dists
120 // check if an upstream artifact based on specific build number has been requested
121 // This is the case of a merge build and the upstream merge build is not yet complete (it is not deemed
122 // a successful build yet). The upstream job is calling this downstream job (with the its build artifiact)
123 if ( params.UPSTREAM_JOB_NAME ) {
124 step ([$class: 'CopyArtifact',
125 projectName: "${params.UPSTREAM_JOB_NAME}",
126 selector: [$class: 'SpecificBuildSelector', buildNumber: "${params.UPSTREAM_JOB_NUMBER}"]
129 //options = get_env_from_build('build.env')
130 // grab the build name/number
131 //build_num = sh(returnStdout:true, script: "cat build.env | awk -F= '/BUILD_NUMBER/{print \$2}'").trim()
132 build_num = ci_helper.get_env_value('build.env','BUILD_NUMBER')
133 component = ci_helper.get_mdg_from_project(ci_helper.get_env_value('build.env','GERRIT_PROJECT'))
135 // the upstream job name contains suffix with the project. Need this stripped off
136 def project_without_branch = params.UPSTREAM_JOB_NAME.split('/')[0]
138 // Remove the previous artifact for this component. Use the new upstream artifact
139 sh "rm -rf pool/${component}"
141 ci_helper.get_archive(params.ARTIFACTORY_SERVER,component,GERRIT_BRANCH, "${project_without_branch} :: ${GERRIT_BRANCH}", build_num)
146 // sign all the components
147 for (component in list) {
148 sh "dpkg-sig --sign builder -k ${GPG_KEY_NAME} pool/${component}/*"
151 // now create the distro
152 for (component in list) {
153 sh "mkdir -p dists/${params.REPO_DISTRO}/${component}/binary-amd64/"
154 sh "apt-ftparchive packages pool/${component} > dists/${params.REPO_DISTRO}/${component}/binary-amd64/Packages"
155 sh "gzip -9fk dists/${params.REPO_DISTRO}/${component}/binary-amd64/Packages"
158 // create and sign the release file
159 sh "apt-ftparchive release dists/${params.REPO_DISTRO} > dists/${params.REPO_DISTRO}/Release"
160 sh "gpg --yes -abs -u ${GPG_KEY_NAME} -o dists/${params.REPO_DISTRO}/Release.gpg dists/${params.REPO_DISTRO}/Release"
162 // copy the public key into the release folder
163 // this pulls the key from the home dir of the current user (jenkins)
164 sh "cp ~/${REPO_KEY_NAME} ."
166 // merge the change logs
168 rm -f changelog/changelog-osm.html
169 [ ! -d changelog ] || for mdgchange in \$(ls changelog); do cat changelog/\$mdgchange >> changelog/changelog-osm.html; done
171 RELEASE_DIR = sh(returnStdout:true, script: 'pwd').trim()
173 // start an apache server to serve up the images
174 http_server_name = "${container_name}-apache"
176 pwd = sh(returnStdout:true, script: 'pwd').trim()
177 repo_base_url = ci_helper.start_http_server(pwd,http_server_name)
180 // now pull the devops package and install in temporary location
181 tempdir = sh(returnStdout: true, script: "mktemp -d").trim()
182 osm_devops_dpkg = sh(returnStdout: true, script: "find . -name osm-devops*.deb").trim()
183 sh "dpkg -x ${osm_devops_dpkg} ${tempdir}"
184 OSM_DEVOPS="${tempdir}/usr/share/osm-devops"
189 if ( params.DO_BUILD ) {
191 sh "make -C docker clean"
192 sh "make -C docker Q= CMD_DOCKER_ARGS= TAG=${container_name} RELEASE=${params.RELEASE} REPOSITORY_BASE=${repo_base_url} REPOSITORY_KEY=${params.REPO_KEY_NAME} REPOSITORY=${params.REPO_DISTRO}"
197 if ( params.DO_INSTALL ) {
200 //will by default always delete containers on complete
201 //sh "jenkins/system/delete_old_containers.sh ${container_name_prefix}"
208 if ( params.COMMIT_ID )
210 commit_id = "-b ${params.COMMIT_ID}"
213 if ( params.REPO_DISTRO )
215 repo_distro = "-r ${params.REPO_DISTRO}"
218 if ( params.REPO_KEY_NAME )
220 repo_key_name = "-k ${params.REPO_KEY_NAME}"
223 if ( params.RELEASE )
225 release = "-R ${params.RELEASE}"
229 export PATH=$PATH:/snap/bin
230 installers/full_install_osm.sh -y -s ${container_name} --test --nolxd --nodocker --nojuju --nohostports --nohostclient \
231 --nodockerbuild -t ${container_name} \
238 ${params.BUILD_FROM_SOURCE}
243 stage_archive = false
244 if ( params.DO_SMOKE ) {
245 stage("OSM Health") {
246 sh "installers/osm_health.sh -s ${container_name}"
249 run_systest(container_name,container_name,"smoke")
250 // archive smoke success until stage_4 is ready
252 if ( ! currentBuild.result.equals('UNSTABLE') ) {
253 stage_archive = keep_artifacts
258 if ( params.DO_STAGE_4 ) {
259 // override stage_archive to only archive on stable
260 stage_archive = false
262 run_systest(container_name,container_name,"openstack_stage_4",params.HIVE_VIM_1)
264 if ( ! currentBuild.result.equals('UNSTABLE') ) {
265 stage_archive = keep_artifacts
270 // override to save the artifacts
271 if ( params.SAVE_ARTIFACTS_OVERRIDE || stage_archive ) {
273 sh "echo ${container_name} > build_version.txt"
274 archiveArtifacts artifacts: "build_version.txt", fingerprint: true
276 // Archive the tested repo
277 dir("${RELEASE_DIR}") {
278 ci_helper.archive(params.ARTIFACTORY_SERVER,RELEASE,GERRIT_BRANCH,'tested')
280 if ( params.DO_DOCKERPUSH ) {
281 stage("Docker Push") {
282 sh "make -C docker push INPUT_TAG=${container_name} TAG=${params.DOCKER_TAG}"
289 println("Caught error!")
291 currentBuild.result = 'FAILURE'
294 sh "docker stop ${http_server_name}"
295 sh "docker rm ${http_server_name}"
297 if ( params.DO_INSTALL ) {
299 if ( !params.SAVE_CONTAINER_ON_FAIL ) {
300 uninstall_osm container_name
305 if ( !params.SAVE_CONTAINER_ON_PASS ) {
306 uninstall_osm container_name