blob: 856945a89bae2384dfd8386b9a62fe7380ccbfc0 [file] [log] [blame]
caviedesje9c2a432026-01-16 10:24:43 +01001/*
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
16def DEFAULT_MODULE_NAME = 'devops'
17
18pipeline {
19 agent { label 'pool' }
garciadeblasf3f204b2026-01-26 10:24:45 +010020 // options { disableConcurrentBuilds() }
caviedesje9c2a432026-01-16 10:24:43 +010021 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
garciadeblas64c47c72026-01-21 09:02:03 +010030 string(name: 'OPENSTACK_BASE_IMAGE', defaultValue: 'ubuntu24.04', description: '')
caviedesje9c2a432026-01-16 10:24:43 +010031 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()
garciadeblasf3f204b2026-01-26 10:24:45 +010047 TEST_IMAGE = 'opensourcemano/devops:19.0'
caviedesje9c2a432026-01-16 10:24:43 +010048 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')
garciadeblascc82cab2026-01-23 12:04:59 +010069 if (!isMergeJob) { sh 'tools/license_scan.sh' } else { echo 'skip the scan for merge' }
caviedesje9c2a432026-01-16 10:24:43 +010070 }
71 }
72 }
73
74 stage('Prepare Test Image') {
75 steps {
76 script {
77 // Use shared test image from registry; no local build needed
garciadeblasf3f204b2026-01-26 10:24:45 +010078 sh "docker pull ${env.DOCKER_REGISTRY}${env.TEST_IMAGE} || true"
caviedesje9c2a432026-01-16 10:24:43 +010079 }
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} \
garciadeblasf3f204b2026-01-26 10:24:45 +010093 ${env.DOCKER_REGISTRY}${env.TEST_IMAGE} \
caviedesje9c2a432026-01-16 10:24:43 +010094 /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} \
garciadeblasf3f204b2026-01-26 10:24:45 +0100104 ${env.DOCKER_REGISTRY}${env.TEST_IMAGE} \
105 /bin/sh -lc 'cd /tests; tools/generatechangelog-pipeline.sh > changelog/changelog-${MDG}.html'
caviedesje9c2a432026-01-16 10:24:43 +0100106 """
107 }
108 }
109 }
110 }
111
caviedesje9c2a432026-01-16 10:24:43 +0100112 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'),
garciadeblasf3f204b2026-01-26 10:24:45 +0100124 string(name: 'CONTAINER_NAME', value: "not-used-from-devops-pipeline"),
caviedesje9c2a432026-01-16 10:24:43 +0100125 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