blob: 0131a86ad73b1c62bbec710c77ebfaa7e616d07a [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
caviedesje9c2a432026-01-16 10:24:43 +010016pipeline {
17 agent { label 'pool' }
garciadeblasf3f204b2026-01-26 10:24:45 +010018 // options { disableConcurrentBuilds() }
caviedesje9c2a432026-01-16 10:24:43 +010019 parameters {
20 // Core Gerrit / multibranch inputs
21 string(name: 'GERRIT_BRANCH', defaultValue: env.BRANCH_NAME ?: 'master', description: '')
22 string(name: 'GERRIT_PROJECT', defaultValue: 'osm/devops', description: '')
23 string(name: 'GERRIT_REFSPEC', defaultValue: env.GERRIT_REFSPEC ?: '', description: '')
24 string(name: 'GERRIT_PATCHSET_REVISION', defaultValue: env.GERRIT_PATCHSET_REVISION ?: '', description: '')
25 string(name: 'DOCKER_ARGS', defaultValue: '', description: 'Extra docker args for docker run')
26
27 // E2E test parameters
garciadeblas64c47c72026-01-21 09:02:03 +010028 string(name: 'OPENSTACK_BASE_IMAGE', defaultValue: 'ubuntu24.04', description: '')
caviedesje9c2a432026-01-16 10:24:43 +010029 string(name: 'OPENSTACK_OSM_FLAVOR', defaultValue: 'osm.sanity', description: '')
30 string(name: 'MODULE_NAME', defaultValue: 'devops', description: 'Name of the module under test')
31
32 // Pipeline control flags
33 booleanParam(name: 'DO_INSTALL', defaultValue: true, description: '')
caviedesje9c2a432026-01-16 10:24:43 +010034 booleanParam(name: 'DO_ROBOT', defaultValue: true, description: '')
35 booleanParam(name: 'SAVE_CONTAINER_ON_FAIL', defaultValue: false, description: '')
36 booleanParam(name: 'SAVE_CONTAINER_ON_PASS', defaultValue: false, description: '')
caviedesje9c2a432026-01-16 10:24:43 +010037 }
38 environment {
39 MDG = "${params.GERRIT_PROJECT?.contains('/') ? params.GERRIT_PROJECT.split('/')[1] : params.GERRIT_PROJECT}"
40 CONTAINER_NAME = "${params.GERRIT_PROJECT}-${params.GERRIT_BRANCH}".toLowerCase()
garciadeblasf3f204b2026-01-26 10:24:45 +010041 TEST_IMAGE = 'opensourcemano/devops:19.0'
caviedesje9c2a432026-01-16 10:24:43 +010042 DOCKER_REGISTRY = 'osm.etsi.org:5050/devops/cicd/'
43 }
44 stages {
45 stage('Prepare') { steps { sh 'env' } }
46
47 stage('Checkout') {
48 steps {
49 checkout scm
50 script {
51 sh "git fetch --tags"
52 if (params.GERRIT_REFSPEC?.trim()) { sh "git fetch origin ${params.GERRIT_REFSPEC}" }
53 if (params.GERRIT_PATCHSET_REVISION?.trim()) { sh "git checkout -f ${params.GERRIT_PATCHSET_REVISION}" }
54 sh "sudo git clean -dfx || git clean -dfx"
55 }
56 }
57 }
58
59 stage('License Scan') {
60 steps {
61 script {
62 def isMergeJob = env.JOB_NAME?.contains('merge')
garciadeblascc82cab2026-01-23 12:04:59 +010063 if (!isMergeJob) { sh 'tools/license_scan.sh' } else { echo 'skip the scan for merge' }
caviedesje9c2a432026-01-16 10:24:43 +010064 }
65 }
66 }
67
68 stage('Prepare Test Image') {
69 steps {
70 script {
71 // Use shared test image from registry; no local build needed
garciadeblasf3f204b2026-01-26 10:24:45 +010072 sh "docker pull ${env.DOCKER_REGISTRY}${env.TEST_IMAGE} || true"
caviedesje9c2a432026-01-16 10:24:43 +010073 }
74 }
75 }
76
77 stage('Tests') {
78 steps {
79 script {
80 def UID = sh(returnStdout: true, script: 'id -u').trim()
81 def GID = sh(returnStdout: true, script: 'id -g').trim()
82 def common = "-v ${env.WORKSPACE}:/tests -e UID=${UID} -e GID=${GID} " + (params.DOCKER_ARGS ?: '')
83
84 stage('Helm Tests') {
85 sh """
86 docker run --rm ${common} \
garciadeblasf3f204b2026-01-26 10:24:45 +010087 ${env.DOCKER_REGISTRY}${env.TEST_IMAGE} \
caviedesje9c2a432026-01-16 10:24:43 +010088 /tests/devops-stages/stage-test.sh
89 """
90 if (fileExists('coverage.xml')) { cobertura coberturaReportFile: 'coverage.xml' }
91 if (fileExists('nosetests.xml')) { junit 'nosetests.xml' }
92 }
93
94 stage('Changelog') {
95 sh 'mkdir -p changelog'
96 sh """
97 docker run --rm ${common} \
garciadeblasf3f204b2026-01-26 10:24:45 +010098 ${env.DOCKER_REGISTRY}${env.TEST_IMAGE} \
99 /bin/sh -lc 'cd /tests; tools/generatechangelog-pipeline.sh > changelog/changelog-${MDG}.html'
caviedesje9c2a432026-01-16 10:24:43 +0100100 """
101 }
102 }
103 }
104 }
105
caviedesje9c2a432026-01-16 10:24:43 +0100106 stage('E2E Test (robot)') {
107 when { expression { return params.DO_ROBOT && !env.JOB_NAME.contains('merge') } }
108 steps {
109 script {
110 def dowstreamJob = "osm-e2e/${params.GERRIT_BRANCH ?: 'master'}"
111 build job: dowstreamJob,
112 parameters: [
113 string(name: 'GERRIT_BRANCH', value: params.GERRIT_BRANCH ?: 'master'),
114 string(name: 'GERRIT_REFSPEC', value: params.GERRIT_REFSPEC ?: ''),
115 string(name: 'OPENSTACK_BASE_IMAGE', value: params.OPENSTACK_BASE_IMAGE),
116 string(name: 'OPENSTACK_OSM_FLAVOR', value: params.OPENSTACK_OSM_FLAVOR),
117 string(name: 'MODULE_NAME', value: params.MODULE_NAME ?: 'devops'),
garciadeblasf3f204b2026-01-26 10:24:45 +0100118 string(name: 'CONTAINER_NAME', value: "not-used-from-devops-pipeline"),
caviedesje9c2a432026-01-16 10:24:43 +0100119 booleanParam(name: 'DO_ROBOT', value: params.DO_ROBOT),
120 booleanParam(name: 'DO_INSTALL', value: params.DO_INSTALL),
121 booleanParam(name: 'SAVE_CONTAINER_ON_FAIL', value: params.SAVE_CONTAINER_ON_FAIL),
122 booleanParam(name: 'SAVE_CONTAINER_ON_PASS', value: params.SAVE_CONTAINER_ON_PASS)
123 ]
124 }
125 }
126 }
127 }
128
129 post {
130 always {
131 // cleanWs()
132 deleteDir()
133 }
134 }
135}