| caviedesj | e9c2a43 | 2026-01-16 10:24:43 +0100 | [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, either express or |
| 11 | implied. |
| 12 | See the License for the specific language governing permissions and |
| 13 | limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | def DEFAULT_MODULE_NAME = 'devops' |
| 17 | |
| 18 | pipeline { |
| 19 | agent { label 'pool' } |
| garciadeblas | f3f204b | 2026-01-26 10:24:45 +0100 | [diff] [blame] | 20 | // options { disableConcurrentBuilds() } |
| caviedesj | e9c2a43 | 2026-01-16 10:24:43 +0100 | [diff] [blame] | 21 | parameters { |
| 22 | // Core Gerrit / multibranch inputs |
| 23 | string(name: 'GERRIT_BRANCH', defaultValue: env.BRANCH_NAME ?: 'master', description: '') |
| 24 | string(name: 'GERRIT_PROJECT', defaultValue: 'osm/devops', description: '') |
| 25 | string(name: 'GERRIT_REFSPEC', defaultValue: env.GERRIT_REFSPEC ?: '', description: '') |
| 26 | string(name: 'GERRIT_PATCHSET_REVISION', defaultValue: env.GERRIT_PATCHSET_REVISION ?: '', description: '') |
| 27 | string(name: 'DOCKER_ARGS', defaultValue: '', description: 'Extra docker args for docker run') |
| 28 | |
| 29 | // E2E test parameters |
| garciadeblas | 64c47c7 | 2026-01-21 09:02:03 +0100 | [diff] [blame] | 30 | string(name: 'OPENSTACK_BASE_IMAGE', defaultValue: 'ubuntu24.04', description: '') |
| caviedesj | e9c2a43 | 2026-01-16 10:24:43 +0100 | [diff] [blame] | 31 | string(name: 'OPENSTACK_OSM_FLAVOR', defaultValue: 'osm.sanity', description: '') |
| 32 | string(name: 'MODULE_NAME', defaultValue: 'devops', description: 'Name of the module under test') |
| 33 | |
| 34 | // Pipeline control flags |
| 35 | booleanParam(name: 'DO_INSTALL', defaultValue: true, description: '') |
| 36 | booleanParam(name: 'DO_DOCKERPUSH', defaultValue: true, description: '') |
| 37 | booleanParam(name: 'DO_ROBOT', defaultValue: true, description: '') |
| 38 | booleanParam(name: 'SAVE_CONTAINER_ON_FAIL', defaultValue: false, description: '') |
| 39 | booleanParam(name: 'SAVE_CONTAINER_ON_PASS', defaultValue: false, description: '') |
| 40 | |
| 41 | // Docker image configuration |
| 42 | string(name: 'IMAGENAME', defaultValue: 'opensourcemano/devops', description: 'Image name for publish (reserved)') |
| 43 | } |
| 44 | environment { |
| 45 | MDG = "${params.GERRIT_PROJECT?.contains('/') ? params.GERRIT_PROJECT.split('/')[1] : params.GERRIT_PROJECT}" |
| 46 | CONTAINER_NAME = "${params.GERRIT_PROJECT}-${params.GERRIT_BRANCH}".toLowerCase() |
| garciadeblas | f3f204b | 2026-01-26 10:24:45 +0100 | [diff] [blame] | 47 | TEST_IMAGE = 'opensourcemano/devops:19.0' |
| caviedesj | e9c2a43 | 2026-01-16 10:24:43 +0100 | [diff] [blame] | 48 | DOCKER_REGISTRY = 'osm.etsi.org:5050/devops/cicd/' |
| 49 | } |
| 50 | stages { |
| 51 | stage('Prepare') { steps { sh 'env' } } |
| 52 | |
| 53 | stage('Checkout') { |
| 54 | steps { |
| 55 | checkout scm |
| 56 | script { |
| 57 | sh "git fetch --tags" |
| 58 | if (params.GERRIT_REFSPEC?.trim()) { sh "git fetch origin ${params.GERRIT_REFSPEC}" } |
| 59 | if (params.GERRIT_PATCHSET_REVISION?.trim()) { sh "git checkout -f ${params.GERRIT_PATCHSET_REVISION}" } |
| 60 | sh "sudo git clean -dfx || git clean -dfx" |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | stage('License Scan') { |
| 66 | steps { |
| 67 | script { |
| 68 | def isMergeJob = env.JOB_NAME?.contains('merge') |
| garciadeblas | cc82cab | 2026-01-23 12:04:59 +0100 | [diff] [blame] | 69 | if (!isMergeJob) { sh 'tools/license_scan.sh' } else { echo 'skip the scan for merge' } |
| caviedesj | e9c2a43 | 2026-01-16 10:24:43 +0100 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | stage('Prepare Test Image') { |
| 75 | steps { |
| 76 | script { |
| 77 | // Use shared test image from registry; no local build needed |
| garciadeblas | f3f204b | 2026-01-26 10:24:45 +0100 | [diff] [blame] | 78 | sh "docker pull ${env.DOCKER_REGISTRY}${env.TEST_IMAGE} || true" |
| caviedesj | e9c2a43 | 2026-01-16 10:24:43 +0100 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | stage('Tests') { |
| 84 | steps { |
| 85 | script { |
| 86 | def UID = sh(returnStdout: true, script: 'id -u').trim() |
| 87 | def GID = sh(returnStdout: true, script: 'id -g').trim() |
| 88 | def common = "-v ${env.WORKSPACE}:/tests -e UID=${UID} -e GID=${GID} " + (params.DOCKER_ARGS ?: '') |
| 89 | |
| 90 | stage('Helm Tests') { |
| 91 | sh """ |
| 92 | docker run --rm ${common} \ |
| garciadeblas | f3f204b | 2026-01-26 10:24:45 +0100 | [diff] [blame] | 93 | ${env.DOCKER_REGISTRY}${env.TEST_IMAGE} \ |
| caviedesj | e9c2a43 | 2026-01-16 10:24:43 +0100 | [diff] [blame] | 94 | /tests/devops-stages/stage-test.sh |
| 95 | """ |
| 96 | if (fileExists('coverage.xml')) { cobertura coberturaReportFile: 'coverage.xml' } |
| 97 | if (fileExists('nosetests.xml')) { junit 'nosetests.xml' } |
| 98 | } |
| 99 | |
| 100 | stage('Changelog') { |
| 101 | sh 'mkdir -p changelog' |
| 102 | sh """ |
| 103 | docker run --rm ${common} \ |
| garciadeblas | f3f204b | 2026-01-26 10:24:45 +0100 | [diff] [blame] | 104 | ${env.DOCKER_REGISTRY}${env.TEST_IMAGE} \ |
| 105 | /bin/sh -lc 'cd /tests; tools/generatechangelog-pipeline.sh > changelog/changelog-${MDG}.html' |
| caviedesj | e9c2a43 | 2026-01-16 10:24:43 +0100 | [diff] [blame] | 106 | """ |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| caviedesj | e9c2a43 | 2026-01-16 10:24:43 +0100 | [diff] [blame] | 112 | stage('E2E Test (robot)') { |
| 113 | when { expression { return params.DO_ROBOT && !env.JOB_NAME.contains('merge') } } |
| 114 | steps { |
| 115 | script { |
| 116 | def dowstreamJob = "osm-e2e/${params.GERRIT_BRANCH ?: 'master'}" |
| 117 | build job: dowstreamJob, |
| 118 | parameters: [ |
| 119 | string(name: 'GERRIT_BRANCH', value: params.GERRIT_BRANCH ?: 'master'), |
| 120 | string(name: 'GERRIT_REFSPEC', value: params.GERRIT_REFSPEC ?: ''), |
| 121 | string(name: 'OPENSTACK_BASE_IMAGE', value: params.OPENSTACK_BASE_IMAGE), |
| 122 | string(name: 'OPENSTACK_OSM_FLAVOR', value: params.OPENSTACK_OSM_FLAVOR), |
| 123 | string(name: 'MODULE_NAME', value: params.MODULE_NAME ?: 'devops'), |
| garciadeblas | f3f204b | 2026-01-26 10:24:45 +0100 | [diff] [blame] | 124 | string(name: 'CONTAINER_NAME', value: "not-used-from-devops-pipeline"), |
| caviedesj | e9c2a43 | 2026-01-16 10:24:43 +0100 | [diff] [blame] | 125 | booleanParam(name: 'DO_ROBOT', value: params.DO_ROBOT), |
| 126 | booleanParam(name: 'DO_INSTALL', value: params.DO_INSTALL), |
| 127 | booleanParam(name: 'SAVE_CONTAINER_ON_FAIL', value: params.SAVE_CONTAINER_ON_FAIL), |
| 128 | booleanParam(name: 'SAVE_CONTAINER_ON_PASS', value: params.SAVE_CONTAINER_ON_PASS) |
| 129 | ] |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | post { |
| 136 | always { |
| 137 | // cleanWs() |
| 138 | deleteDir() |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |