blob: 156fe62201ca4fafa6c3b5eb480aa5069b025da3 [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 """
caviedesjcfed21d2026-02-26 12:45:44 +010090 if (fileExists('coverage.xml')) {
91 recordCoverage tools: [[
92 parser: 'COBERTURA',
93 pattern: 'coverage.xml'
94 ]], sourceDirectories: []
95 }
96
97 if (fileExists('nosetests.xml')) {
98 junit 'nosetests.xml'
99 }
caviedesje9c2a432026-01-16 10:24:43 +0100100 }
101
102 stage('Changelog') {
103 sh 'mkdir -p changelog'
104 sh """
105 docker run --rm ${common} \
garciadeblasf3f204b2026-01-26 10:24:45 +0100106 ${env.DOCKER_REGISTRY}${env.TEST_IMAGE} \
107 /bin/sh -lc 'cd /tests; tools/generatechangelog-pipeline.sh > changelog/changelog-${MDG}.html'
caviedesje9c2a432026-01-16 10:24:43 +0100108 """
109 }
110 }
111 }
112 }
113
caviedesje9c2a432026-01-16 10:24:43 +0100114 stage('E2E Test (robot)') {
115 when { expression { return params.DO_ROBOT && !env.JOB_NAME.contains('merge') } }
116 steps {
117 script {
118 def dowstreamJob = "osm-e2e/${params.GERRIT_BRANCH ?: 'master'}"
119 build job: dowstreamJob,
120 parameters: [
121 string(name: 'GERRIT_BRANCH', value: params.GERRIT_BRANCH ?: 'master'),
122 string(name: 'GERRIT_REFSPEC', value: params.GERRIT_REFSPEC ?: ''),
123 string(name: 'OPENSTACK_BASE_IMAGE', value: params.OPENSTACK_BASE_IMAGE),
124 string(name: 'OPENSTACK_OSM_FLAVOR', value: params.OPENSTACK_OSM_FLAVOR),
125 string(name: 'MODULE_NAME', value: params.MODULE_NAME ?: 'devops'),
garciadeblasf3f204b2026-01-26 10:24:45 +0100126 string(name: 'CONTAINER_NAME', value: "not-used-from-devops-pipeline"),
caviedesje9c2a432026-01-16 10:24:43 +0100127 booleanParam(name: 'DO_ROBOT', value: params.DO_ROBOT),
128 booleanParam(name: 'DO_INSTALL', value: params.DO_INSTALL),
129 booleanParam(name: 'SAVE_CONTAINER_ON_FAIL', value: params.SAVE_CONTAINER_ON_FAIL),
130 booleanParam(name: 'SAVE_CONTAINER_ON_PASS', value: params.SAVE_CONTAINER_ON_PASS)
131 ]
132 }
133 }
134 }
135 }
136
137 post {
138 always {
139 // cleanWs()
140 deleteDir()
141 }
142 }
143}