Move lcm certificate to lcm folder in OSM helm chart
[osm/devops.git] / jenkins / ci-pipelines / ci_stage_2.groovy
1 /* Copyright 2017 Sandvine
2  *
3  * All Rights Reserved.
4  *
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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
15  *   under the License.
16  */
17
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}"
22
23     sh "git fetch --tags"
24     sh "git fetch origin ${refspec}"
25     if (GERRIT_PATCHSET_REVISION.size() > 0 ) {
26         sh "git checkout -f ${revision}"
27     }
28     sh "sudo git clean -dfx"
29 }
30
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"
34     def isMergeJob = JOB_NAME.contains('merge')
35
36     stage('Prepare') {
37         sh 'env'
38     }
39
40     stage('Checkout') {
41         project_checkout(url_prefix,project,refspec,revision)
42     }
43
44     stage('License Scan') {
45       if (!isMergeJob) {
46         sh "devops/tools/license_scan.sh"
47       }
48       else {
49         println("skip the scan for merge")
50       }
51     }
52
53     stage('Release Note Check') {
54       if (fileExists('devops-stages/stage-releasenote.sh')) {
55         if (!isMergeJob) {
56             sh "devops-stages/stage-releasenote.sh"
57         }
58         else {
59             println("Not checking release notes for merge job")
60         }
61       }
62       else {
63           println("No releasenote check present")
64       }
65     }
66
67     container_name = "${project}-${branch}".toLowerCase()
68
69     stage('Docker-Build') {
70         APT_PROXY = "http://172.21.1.1:3142"
71         sh "docker build --build-arg APT_PROXY=${APT_PROXY} -t ${container_name} ."
72     }
73
74     UID = sh(returnStdout:true,  script: 'id -u').trim()
75     GID = sh(returnStdout:true,  script: 'id -g').trim()
76     withDockerContainer(image: "${container_name}", args: docker_args + " -u root") {
77         stage('Test') {
78             sh "groupadd -o -g $GID -r jenkins"
79             sh "useradd -o -u $UID -d `pwd` -r -g jenkins jenkins"
80             sh "echo '#! /bin/sh' > /usr/bin/mesg"
81             sh "chmod 755 /usr/bin/mesg"
82             sh "runuser jenkins -c devops-stages/stage-test.sh"
83             if (fileExists('coverage.xml')) {
84                 cobertura coberturaReportFile: 'coverage.xml'
85             }
86             if (fileExists('nosetests.xml')) {
87                 junit 'nosetests.xml'
88             }
89         }
90         stage('Build') {
91             sh(returnStdout:true,
92                 script: "runuser jenkins -c devops-stages/stage-build.sh").trim()
93         }
94         stage('Archive') {
95             sh "runuser jenkins -c 'mkdir -p changelog'"
96             sh "runuser jenkins -c \"devops/tools/generatechangelog-pipeline.sh > changelog/changelog-${mdg}.html\""
97             sh(returnStdout:true,
98                 script: "runuser jenkins -c devops-stages/stage-archive.sh").trim()
99             ci_helper.archive(artifactory_server,mdg,branch,'untested')
100         }
101     }
102
103     if ( do_stage_3 ) {
104         stage('Build System') {
105             def downstream_params_stage_3 = [
106                 string(name: 'GERRIT_BRANCH', value: "${branch}"),
107                 string(name: 'INSTALLER', value: "Default" ),
108                 string(name: 'OPENSTACK_BASE_IMAGE', value: "ubuntu22.04" ),
109                 string(name: 'OPENSTACK_OSM_FLAVOR', value: "osm.sanity" ),
110                 string(name: 'UPSTREAM_JOB_NAME', value: "${JOB_NAME}" ),
111                 string(name: 'UPSTREAM_JOB_NUMBER', value: "${BUILD_NUMBER}" ),
112                 booleanParam(name: 'DO_STAGE_4', value: do_stage_4 ),
113                 booleanParam(name: 'TRY_JUJU_INSTALLATION', value: false),
114                 booleanParam(name: 'TRY_OLD_SERVICE_ASSURANCE', value: false),
115             ]
116             stage_3_job = "osm-stage_3"
117             if ( JOB_NAME.contains('merge') ) {
118                 stage_3_job += '-merge'
119             }
120
121             // callout to stage_3. This is the system build
122             result = build job: "${stage_3_job}/${branch}", parameters: downstream_params_stage_3, propagate: true
123             if (result.getResult() != 'SUCCESS') {
124                 project = result.getProjectName()
125                 build = result.getNumber()
126                 error("${project} build ${build} failed")
127             }
128         }
129     }
130 }
131
132 return this