Merge "Modified fixtures to make generalise VIM accessfor vim create"
[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 origin ${refspec}"
24     if (GERRIT_PATCHSET_REVISION.size() > 0 ) {
25         sh "git checkout -f ${revision}"
26     }
27 }
28
29 def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,build_system,artifactory_server) {
30     println("build_system = ${build_system}")
31     ci_helper = load "devops/jenkins/ci-pipelines/ci_helper.groovy"
32
33     stage('Prepare') {
34         sh 'env'
35     }
36
37     stage('Checkout') {
38         project_checkout(url_prefix,project,refspec,revision)
39     }
40
41     stage('License Scan') {
42         sh "devops/tools/license_scan.sh"
43     }
44
45     container_name = "${project}-${branch}".toLowerCase()
46
47     stage('Docker-Build') {
48         sh '''
49            echo RUN groupadd -o -g $(id -g) -r jenkins >> Dockerfile
50            echo RUN useradd -o -u $(id -u) --create-home -r -g  jenkins jenkins >> Dockerfile
51            '''
52         sh "docker build -t ${container_name} ."
53     }
54
55     withDockerContainer("${container_name}") {
56         stage('Test') {
57             sh 'devops-stages/stage-test.sh'
58         }
59         stage('Build') {
60             sh(returnStdout:true,  script: 'devops-stages/stage-build.sh').trim()
61         }
62     }
63
64     stage('Archive') {
65         sh(returnStdout:true,  script: 'devops-stages/stage-archive.sh').trim()
66         ci_helper.archive(artifactory_server,mdg,branch,'untested')
67     }
68
69     if ( build_system ) {
70
71         stage('Build System') {
72             def downstream_params_stage_3 = [
73                 string(name: 'GERRIT_BRANCH', value: "${branch}"),
74                 string(name: 'UPSTREAM_JOB_NAME', value: "${JOB_NAME}" ),
75                 string(name: 'UPSTREAM_JOB_NUMBER', value: "${BUILD_NUMBER}" ),
76             ]
77
78             // callout to stage_3.  This is the system build
79             result = build job: "osm-stage_3/${branch}", parameters: downstream_params_stage_3, propagate: true
80             if (result.getResult() != 'SUCCESS') {
81                 project = result.getProjectName()
82                 build = result.getNumber()
83                 error("${project} build ${build} failed")
84             }
85         }
86     }
87
88 }
89
90 return this