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 * 1. Bug 699 : Jayant Madavi, Mrityunjay Yadav : JM00553988@techmahindra.com : 23-july-2019 : Improvement to the code, now using post syntax
19 * 2. Jayant Madavi : 26-july-2019 : optimization to the previous check-in added currentBuild.result = 'SUCCESS'. TODO: code would be better * if we use pipeline declarative
22 stage_3_merge_result = ''
23 def Get_MDG(project) {
25 def values = project.split('/')
26 if ( values.size() > 1 ) {
29 // no prefix, likely just the project name then
33 node("${params.NODE}") {
35 mdg = Get_MDG("${GERRIT_PROJECT}")
36 println("MDG is ${mdg}")
38 if ( params.PROJECT_URL_PREFIX == null )
40 params.PROJECT_URL_PREFIX = 'https://osm.etsi.org/gerrit'
44 // default to stage_2 (patchset)
45 def stage_name = "stage_2"
48 switch(GERRIT_EVENT_TYPE) {
50 stage_name = "stage_2-merge"
53 case "patchset-created":
54 stage_name = "stage_2"
59 println("No gerrit event found")
62 // pipeline running from gerrit trigger.
63 // kickoff the downstream multibranch pipeline
64 def downstream_params = [
65 string(name: 'GERRIT_BRANCH', value: GERRIT_BRANCH),
66 string(name: 'GERRIT_PROJECT', value: GERRIT_PROJECT),
67 string(name: 'GERRIT_REFSPEC', value: GERRIT_REFSPEC),
68 string(name: 'GERRIT_PATCHSET_REVISION', value: GERRIT_PATCHSET_REVISION),
69 string(name: 'INSTALLER', value: params.INSTALLER),
70 string(name: 'OPENSTACK_BASE_IMAGE', value: params.OPENSTACK_BASE_IMAGE),
71 string(name: 'OPENSTACK_OSM_FLAVOR', value: params.OPENSTACK_OSM_FLAVOR),
72 string(name: 'PROJECT_URL_PREFIX', value: params.PROJECT_URL_PREFIX),
73 string(name: 'DOCKER_TAG', value: params.DOCKER_TAG),
74 booleanParam(name: 'TEST_INSTALL', value: params.TEST_INSTALL),
76 if ( params.DO_ROBOT )
78 downstream_params.add(booleanParam(name: 'DO_ROBOT', value: params.DO_ROBOT))
80 if ( params.ROBOT_TAG_NAME )
82 downstream_params.add(string(name: 'ROBOT_TAG_NAME', value: params.ROBOT_TAG_NAME))
87 // go directly to stage 3 (osm system)
88 stage_name = params.STAGE
90 if ( ! params.TEST_INSTALL )
92 println("disabling stage_3 invocation")
95 // in this case, since this is for daily jobs, the pass threshold for robot tests should be adapted
96 downstream_params.add(string(name: 'ROBOT_PASS_THRESHOLD', value: '99.0'))
98 // callout to stage_2. This is a multi-branch pipeline.
99 downstream_job_name = "${mdg}-${stage_name}/${GERRIT_BRANCH}"
101 println("Downstream job: ${downstream_job_name}")
102 println("Downstream parameters: ${downstream_params}")
103 currentBuild.result = 'SUCCESS'
105 stage_3_merge_result = build job: "${downstream_job_name}", parameters: downstream_params, propagate: true
106 if (stage_3_merge_result.getResult() != 'SUCCESS') {
107 project = stage_3_merge_result.getProjectName()
108 build = stage_3_merge_result.getNumber()
109 // Jayant if the build fails the below error will cause the pipeline to terminate.
110 // error("${project} build ${build} failed")
111 currentBuild.result = stage_3_merge_result.getResult()
115 echo 'Exception in stage_1'
116 currentBuild.result = 'FAILURE'
120 if ((currentBuild.result != 'SUCCESS') && (env.JOB_NAME.startsWith('daily-stage_4'))){
122 subject: "[OSM-Jenkins] Job: ${env.JOB_NAME} Build: ${env.BUILD_NUMBER} Result: ${currentBuild.result}",
123 body: """ Check console output at "${env.BUILD_URL}" """,
124 to: 'OSM_MDL@list.etsi.org',
125 recipientProviders: [culprits()]
130 echo "Failure in executing email"