bug 792 added version for pytest==4.6.3 fixed
[osm/devops.git] / jenkins / ci-pipelines / ci_stage_1.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 stage_3_merge_result = ''
19 def Get_MDG(project) {
20     // split the project.
21     def values = project.split('/')
22     if ( values.size() > 1 ) {
23         return values[1]
24     }
25     // no prefix, likely just the project name then
26     return project
27 }
28
29 node("${params.NODE}") {
30
31     mdg = Get_MDG("${GERRIT_PROJECT}")
32     println("MDG is ${mdg}")
33
34     if ( params.PROJECT_URL_PREFIX == null )
35     {
36         params.PROJECT_URL_PREFIX  = 'https://osm.etsi.org/gerrit'
37     }
38
39     stage('downstream') {
40         // default to stage_2 (patchset)
41         def stage_name = "stage_2"
42
43         try {
44             switch(GERRIT_EVENT_TYPE) {
45                 case "change-merged":
46                    stage_name = "stage_2-merge"
47                    break
48
49                 case "patchset-created":
50                    stage_name = "stage_2"
51                    break
52             }
53         }
54         catch(caughtError) {
55             println("No gerrit event found")
56         }
57
58         do_stage_4 = false
59         if (params.DO_STAGE_4)
60         {
61             do_stage_4 = params.DO_STAGE_4
62         }
63
64         // pipeline running from gerrit trigger.
65         // kickoff the downstream multibranch pipeline
66         def downstream_params = [
67             string(name: 'GERRIT_BRANCH', value: GERRIT_BRANCH),
68             string(name: 'GERRIT_PROJECT', value: GERRIT_PROJECT),
69             string(name: 'GERRIT_REFSPEC', value: GERRIT_REFSPEC),
70             string(name: 'GERRIT_PATCHSET_REVISION', value: GERRIT_PATCHSET_REVISION),
71             string(name: 'PROJECT_URL_PREFIX', value: params.PROJECT_URL_PREFIX),
72             booleanParam(name: 'TEST_INSTALL', value: params.TEST_INSTALL),
73             booleanParam(name: 'DO_STAGE_4', value: do_stage_4),
74         ]
75      
76         if ( params.STAGE )
77         {
78             // go directly to stage 3 (osm system)
79             stage_name = params.STAGE
80             mdg = "osm"
81             if ( ! params.TEST_INSTALL )
82             {
83                 println("disabling stage_3 invocation")
84                 return
85             }
86         }
87         // callout to stage_2.  This is a multi-branch pipeline.
88         downstream_job_name = "${mdg}-${stage_name}/${GERRIT_BRANCH}"
89
90         println("TEST_INSTALL = ${params.TEST_INSTALL}, downstream job: ${downstream_job_name}")
91
92         stage_3_merge_result = build job: "${downstream_job_name}", parameters: downstream_params, propagate: true
93         if (stage_3_merge_result.getResult() != 'SUCCESS') {
94             project = stage_3_merge_result.getProjectName()
95             build = stage_3_merge_result.getNumber()
96             // Jayant if the build fails the below error will cause the pipeline to terminate. 
97                         // error("${project} build ${build} failed")
98         }
99     }
100         stage('Send Email') {
101         if((stage_3_merge_result.getResult() != 'SUCCESS') && (${env.JOB_NAME} == 'daily-stage_4')){
102             emailext (
103                 subject: "[OSM-Jenkins] Job: ${env.JOB_NAME} Build: ${env.BUILD_NUMBER} Result: ${stage_3_merge_result.getResult()}",
104                 body: """ Check console output at "${env.BUILD_URL}"  """,
105                 to: 'OSM_MDL@list.etsi.org',
106                 recipientProviders: [culprits()]
107             )
108         }
109     }
110 }