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 project_checkout(url_prefix,project,refspec,revision) {
19 // checkout the project
20 // this is done automaticaly by the multibranch pipeline plugin
21 // git url: "${url_prefix}/${project}"
24 sh "git fetch origin ${refspec}"
25 if (GERRIT_PATCHSET_REVISION.size() > 0 ) {
26 sh "git checkout -f ${revision}"
28 sh "sudo git clean -dfx"
31 def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifactory_server,docker_args="",do_stage_4=false) {
32 println("do_stage_3= ${do_stage_3}")
33 ci_helper = load "devops/jenkins/ci-pipelines/ci_helper.groovy"
40 project_checkout(url_prefix,project,refspec,revision)
43 stage('License Scan') {
44 if (!JOB_NAME.contains('merge')) {
45 sh "devops/tools/license_scan.sh"
48 println("skip the scan for merge")
52 container_name = "${project}-${branch}".toLowerCase()
54 stage('Docker-Build') {
55 APT_PROXY = "http://172.21.1.1:3142"
56 sh "docker build --build-arg APT_PROXY=${APT_PROXY} -t ${container_name} ."
59 UID = sh(returnStdout:true, script: 'id -u').trim()
60 GID = sh(returnStdout:true, script: 'id -g').trim()
61 withDockerContainer(image: "${container_name}", args: docker_args + " -u root") {
63 sh "groupadd -o -g $GID -r jenkins"
64 sh "useradd -o -u $UID -d `pwd` -r -g jenkins jenkins"
65 sh "echo '#! /bin/sh' > /usr/bin/mesg"
66 sh "chmod 755 /usr/bin/mesg"
67 sh "runuser jenkins -c devops-stages/stage-test.sh"
68 if (fileExists('coverage.xml')) {
69 cobertura coberturaReportFile: 'coverage.xml'
71 if (fileExists('nosetests.xml')) {
77 script: "runuser jenkins -c devops-stages/stage-build.sh").trim()
80 sh "runuser jenkins -c 'mkdir -p changelog'"
81 sh "runuser jenkins -c \"devops/tools/generatechangelog-pipeline.sh > changelog/changelog-${mdg}.html\""
83 script: "runuser jenkins -c devops-stages/stage-archive.sh").trim()
84 ci_helper.archive(artifactory_server,mdg,branch,'untested')
88 if (fileExists('snap/snapcraft.yaml')) {
90 sh "docker pull snapcore/snapcraft:stable"
91 sh "sudo rm -rf ${WORKSPACE}/stage/ ${WORKSPACE}/parts/ ${WORKSPACE}/prime/ ${WORKSPACE}/*.snap"
92 sh "sudo snapcraft clean --use-lxd"
93 sh "snapcraft --use-lxd"
94 sh "mv ${WORKSPACE}/${mdg}_*.snap ${WORKSPACE}/${mdg}.snap"
95 sh "sudo rm -rf ${WORKSPACE}/stage/ ${WORKSPACE}/parts/ ${WORKSPACE}/prime/"
98 if ( !JOB_NAME.contains('merge') ) {
99 REV="/"+"${GERRIT_REFSPEC}".replaceAll('/','-')
102 if (BRANCH_NAME.startsWith("v")) {
103 channel=BRANCH_NAME.substring(1)
104 } else if (BRANCH_NAME!="master") {
105 REV="/"+BRANCH_NAME+REV.replaceAll('/','-')
108 sh "sudo docker run -v ~/.snapcraft:/snapcraft -v ${WORKSPACE}:/build " +
109 "-w /build snapcore/snapcraft:stable /bin/bash -c " +
110 "\"snapcraft login --with /snapcraft/config ; snapcraft push --release=${channel}/edge${REV} ${mdg}.snap\""
111 sh "sudo rm -rf ${WORKSPACE}/*.snap"
116 stage('Build System') {
117 def downstream_params_stage_3 = [
118 string(name: 'GERRIT_BRANCH', value: "${branch}"),
119 string(name: 'INSTALLER', value: "Default" ),
120 string(name: 'OPENSTACK_BASE_IMAGE', value: "ubuntu20.04" ),
121 string(name: 'UPSTREAM_JOB_NAME', value: "${JOB_NAME}" ),
122 string(name: 'UPSTREAM_JOB_NUMBER', value: "${BUILD_NUMBER}" ),
123 booleanParam(name: 'DO_STAGE_4', value: do_stage_4 )
125 stage_3_job = "osm-stage_3"
126 if ( JOB_NAME.contains('merge') ) {
127 stage_3_job += '-merge'
130 // callout to stage_3. This is the system build
131 result = build job: "${stage_3_job}/${branch}", parameters: downstream_params_stage_3, propagate: true
132 if (result.getResult() != 'SUCCESS') {
133 project = result.getProjectName()
134 build = result.getNumber()
135 error("${project} build ${build} failed")