| tierno | d125caf | 2018-11-22 16:05:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | you may not use this file except in compliance with the License. |
| 4 | You may obtain a copy of the License at |
| 5 | |
| 6 | http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | |
| 8 | Unless required by applicable law or agreed to in writing, software |
| 9 | distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 11 | implied. |
| 12 | See the License for the specific language governing permissions and |
| 13 | limitations under the License. |
| 14 | */ |
| Mike Marchetti | 80d61ec | 2018-04-18 13:54:10 -0400 | [diff] [blame] | 15 | properties([ |
| 16 | parameters([ |
| 17 | string(defaultValue: env.BRANCH_NAME, description: '', name: 'GERRIT_BRANCH'), |
| 18 | string(defaultValue: 'osm/NBI', description: '', name: 'GERRIT_PROJECT'), |
| 19 | string(defaultValue: env.GERRIT_REFSPEC, description: '', name: 'GERRIT_REFSPEC'), |
| 20 | string(defaultValue: env.GERRIT_PATCHSET_REVISION, description: '', name: 'GERRIT_PATCHSET_REVISION'), |
| garciadeblas | 5ec88ef | 2020-09-11 14:04:23 +0000 | [diff] [blame] | 21 | string(defaultValue: 'patchset-created', description: '', name: 'GERRIT_EVENT_TYPE'), |
| Mike Marchetti | 80d61ec | 2018-04-18 13:54:10 -0400 | [diff] [blame] | 22 | string(defaultValue: 'https://osm.etsi.org/gerrit', description: '', name: 'PROJECT_URL_PREFIX'), |
| 23 | booleanParam(defaultValue: false, description: '', name: 'TEST_INSTALL'), |
| 24 | string(defaultValue: 'artifactory-osm', description: '', name: 'ARTIFACTORY_SERVER'), |
| 25 | ]) |
| 26 | ]) |
| 27 | |
| 28 | def devops_checkout() { |
| 29 | dir('devops') { |
| 30 | git url: "${PROJECT_URL_PREFIX}/osm/devops", branch: params.GERRIT_BRANCH |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | node('docker') { |
| garciadeblas | 30b9756 | 2020-09-11 09:13:47 +0000 | [diff] [blame] | 35 | stage('CURRENT PIPELINE') { |
| 36 | checkout scm |
| 37 | devops_checkout() |
| Mike Marchetti | 80d61ec | 2018-04-18 13:54:10 -0400 | [diff] [blame] | 38 | |
| garciadeblas | 30b9756 | 2020-09-11 09:13:47 +0000 | [diff] [blame] | 39 | ci_stage_2 = load "devops/jenkins/ci-pipelines/ci_stage_2.groovy" |
| 40 | ci_stage_2.ci_pipeline('NBI', |
| 41 | params.PROJECT_URL_PREFIX, |
| 42 | params.GERRIT_PROJECT, |
| 43 | params.GERRIT_BRANCH, |
| 44 | params.GERRIT_REFSPEC, |
| 45 | params.GERRIT_PATCHSET_REVISION, |
| 46 | // params.TEST_INSTALL, |
| garciadeblas | 6c7d955 | 2020-09-11 12:43:15 +0000 | [diff] [blame] | 47 | false, |
| garciadeblas | 30b9756 | 2020-09-11 09:13:47 +0000 | [diff] [blame] | 48 | params.ARTIFACTORY_SERVER) |
| 49 | } |
| 50 | stage('NEW PIPELINE') { |
| garciadeblas | 8c5be50 | 2020-09-11 13:56:42 +0000 | [diff] [blame] | 51 | // a devops changes in new-pipeline branch is required to receive GERRIT_EVENT_TYPE |
| 52 | // https://osm.etsi.org/gerrit/#/c/osm/devops/+/9701/ |
| 53 | // Meanwhile, stage_name is predefined |
| 54 | def stage_name = "patchset" |
| garciadeblas | 30b9756 | 2020-09-11 09:13:47 +0000 | [diff] [blame] | 55 | try { |
| 56 | switch(GERRIT_EVENT_TYPE) { |
| 57 | case "change-merged": |
| 58 | stage_name = "merge" |
| 59 | break |
| 60 | |
| 61 | case "patchset-created": |
| 62 | stage_name = "patchset" |
| 63 | break |
| 64 | } |
| 65 | } |
| 66 | catch(caughtError) { |
| 67 | println("No gerrit event found") |
| 68 | } |
| 69 | |
| 70 | def downstream_params = [ |
| 71 | string(name: 'GERRIT_BRANCH', value: params.GERRIT_BRANCH), |
| 72 | string(name: 'GERRIT_PROJECT', value: params.GERRIT_PROJECT), |
| 73 | string(name: 'GERRIT_REFSPEC', value: params.GERRIT_REFSPEC), |
| 74 | string(name: 'GERRIT_PATCHSET_REVISION', value: params.GERRIT_PATCHSET_REVISION), |
| 75 | string(name: 'PROJECT_URL_PREFIX', value: params.PROJECT_URL_PREFIX), |
| 76 | booleanParam(name: 'TEST_INSTALL', value: params.TEST_INSTALL), |
| 77 | // next params will have to be updated with the proper values |
| 78 | string(name: 'IMAGENAME', value: 'opensourcemano/nbi'), |
| garciadeblas | bcadd32 | 2020-09-11 12:48:25 +0000 | [diff] [blame] | 79 | string(name: 'DOCKER_REGISTRY', value: 'localhost:5000'), |
| garciadeblas | 30b9756 | 2020-09-11 09:13:47 +0000 | [diff] [blame] | 80 | string(name: 'DOCKER_REGISTRY_PROTOCOL', value: 'http://'), |
| 81 | string(name: 'DOCKER_CREDENTIALS', value: '') |
| 82 | ] |
| 83 | |
| 84 | downstream_job_name = "NBI-${stage_name}" |
| 85 | echo "Triggering NEW PIPELINE" |
| 86 | build job: "${downstream_job_name}", parameters: downstream_params |
| 87 | // build job: "${downstream_job_name}", parameters: downstream_params, propagate: true |
| 88 | // It calls the new pipeline defined in Jenkinsfile.new |
| 89 | // |
| 90 | //build job: '<Job name>', parameters: [[$class: 'StringParameterValue', name: 'param1', value: 'test_param']] |
| 91 | } |
| Mike Marchetti | 80d61ec | 2018-04-18 13:54:10 -0400 | [diff] [blame] | 92 | } |
| garciadeblas | 30b9756 | 2020-09-11 09:13:47 +0000 | [diff] [blame] | 93 | |