blob: 31e7dbf88eafddc4eb197d472d21cec8a0cb5344 [file] [log] [blame]
garciadeblasf35062b2025-12-23 22:57:08 +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
caviedesj4ab749c2026-01-08 18:06:21 +010016def DEFAULT_MODULE_NAME = 'im'
garciadeblasf35062b2025-12-23 22:57:08 +010017
caviedesj4ab749c2026-01-08 18:06:21 +010018pipeline {
19 agent { label 'pool' }
20 options { disableConcurrentBuilds() }
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/im', 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: 'PROJECT_URL_PREFIX', defaultValue: 'https://osm.etsi.org/gerrit', description: '')
28 string(name: 'DOCKER_ARGS', defaultValue: '', description: 'Extra docker args for docker run')
29
30 // E2E test parameters
caviedesj07232d62026-01-19 17:37:45 +010031 string(name: 'OPENSTACK_BASE_IMAGE', defaultValue: 'ubuntu24.04', description: '')
caviedesj4ab749c2026-01-08 18:06:21 +010032 string(name: 'OPENSTACK_OSM_FLAVOR', defaultValue: 'osm.sanity', description: '')
33
34 booleanParam(name: 'DO_INSTALL', defaultValue: true, description: '')
35 booleanParam(name: 'DO_ROBOT', defaultValue: true, description: '')
36 string(name: 'MODULE_NAME', defaultValue: 'IM', description: 'Name of the module under test')
37
38 booleanParam(name: 'SAVE_CONTAINER_ON_FAIL', defaultValue: false, description: '')
39 booleanParam(name: 'SAVE_CONTAINER_ON_PASS', defaultValue: false, description: '')
40 }
41 environment {
42 MDG = "${params.GERRIT_PROJECT?.contains('/') ? params.GERRIT_PROJECT.split('/')[1] : params.GERRIT_PROJECT}"
43 CONTAINER_NAME = "${params.GERRIT_PROJECT}-${params.GERRIT_BRANCH}".toLowerCase()
44 TEST_IMAGE = 'overdrive3000/tox-osm:v1.6'
45 DOCKER_REGISTRY = 'osm.etsi.org:5050/devops/cicd/'
46 }
47 stages {
48 stage('Prepare') { steps { sh 'env' } }
49
50 stage('Checkout') {
51 steps {
52 checkout scm
53 script {
54 sh "git fetch --tags"
55 if (params.GERRIT_REFSPEC?.trim()) { sh "git fetch origin ${params.GERRIT_REFSPEC}" }
56 if (params.GERRIT_PATCHSET_REVISION?.trim()) { sh "git checkout -f ${params.GERRIT_PATCHSET_REVISION}" }
57 sh "sudo git clean -dfx || git clean -dfx"
58 }
59 }
60 }
61
62 stage('Clone devops (central)') {
63 steps {
64 dir('devops') {
65 sh "git init ."
66 sh "git remote remove origin || true"
67 sh "git remote add origin ${params.PROJECT_URL_PREFIX}/osm/devops"
68 sh "git fetch --depth=1 origin ${params.GERRIT_BRANCH}"
69 sh "git checkout -f FETCH_HEAD"
70 }
71 }
72 }
73
74 stage('License Scan') {
75 steps {
76 script {
77 def isMergeJob = env.JOB_NAME?.contains('merge')
78 if (!isMergeJob) { sh 'devops/tools/license_scan.sh' } else { echo 'skip the scan for merge' }
79 }
80 }
81 }
82
83 stage('Prepare Test Image') {
84 steps {
85 script {
86 // Use shared test image from registry; no local build needed
87 sh "docker pull ${env.TEST_IMAGE} || true"
88 }
89 }
90 }
91
92 stage('Tests') {
93 steps {
94 script {
95 def UID = sh(returnStdout: true, script: 'id -u').trim()
96 def GID = sh(returnStdout: true, script: 'id -g').trim()
97 def common = "-v ${env.WORKSPACE}:/tests -e UID=${UID} -e GID=${GID} " + (params.DOCKER_ARGS ?: '')
98
99 stage('Linting Tests') {
100 sh """
101 docker run --rm ${common} \
102 ${env.TEST_IMAGE} \
103 /tests/devops-stages/stage-lint.sh
104 """
105 }
106
107 stage('Unit Tests') {
108 sh """
109 docker run --rm ${common} \
110 ${env.TEST_IMAGE} \
111 /tests/devops-stages/stage-test.sh
112 """
113 if (fileExists('coverage.xml')) { cobertura coberturaReportFile: 'coverage.xml' }
114 if (fileExists('nosetests.xml')) { junit 'nosetests.xml' }
115 }
116
117 stage('Changelog') {
118 sh 'mkdir -p changelog'
119 sh """
120 docker run --rm ${common} \
121 ${env.TEST_IMAGE} \
122 /bin/sh -lc 'devops/tools/generatechangelog-pipeline.sh > /tests/changelog/changelog-${MDG}.html'
123 """
124 }
125 }
126 }
127 }
128 }
129
130 post {
131 always {
132 // cleanWs()
133 deleteDir()
134 }
135 }
136}