blob: ddbd7afe48b0299e47111d09e72443e0a6952196 [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 +010016pipeline {
17 agent { label 'pool' }
18 options { disableConcurrentBuilds() }
19 parameters {
20 // Core Gerrit / multibranch inputs
21 string(name: 'GERRIT_BRANCH', defaultValue: env.BRANCH_NAME ?: 'master', description: '')
22 string(name: 'GERRIT_PROJECT', defaultValue: 'osm/im', 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: 'PROJECT_URL_PREFIX', defaultValue: 'https://osm.etsi.org/gerrit', description: '')
26 string(name: 'DOCKER_ARGS', defaultValue: '', description: 'Extra docker args for docker run')
caviedesj4ab749c2026-01-08 18:06:21 +010027 }
28 environment {
29 MDG = "${params.GERRIT_PROJECT?.contains('/') ? params.GERRIT_PROJECT.split('/')[1] : params.GERRIT_PROJECT}"
caviedesje170e962026-02-12 19:07:13 +010030 TEST_IMAGE = 'opensourcemano/tox-osm:19.0'
caviedesj4ab749c2026-01-08 18:06:21 +010031 }
32 stages {
33 stage('Prepare') { steps { sh 'env' } }
34
35 stage('Checkout') {
36 steps {
37 checkout scm
38 script {
39 sh "git fetch --tags"
40 if (params.GERRIT_REFSPEC?.trim()) { sh "git fetch origin ${params.GERRIT_REFSPEC}" }
41 if (params.GERRIT_PATCHSET_REVISION?.trim()) { sh "git checkout -f ${params.GERRIT_PATCHSET_REVISION}" }
42 sh "sudo git clean -dfx || git clean -dfx"
43 }
44 }
45 }
46
47 stage('Clone devops (central)') {
48 steps {
49 dir('devops') {
50 sh "git init ."
51 sh "git remote remove origin || true"
52 sh "git remote add origin ${params.PROJECT_URL_PREFIX}/osm/devops"
53 sh "git fetch --depth=1 origin ${params.GERRIT_BRANCH}"
54 sh "git checkout -f FETCH_HEAD"
55 }
56 }
57 }
58
59 stage('License Scan') {
60 steps {
61 script {
62 def isMergeJob = env.JOB_NAME?.contains('merge')
63 if (!isMergeJob) { sh 'devops/tools/license_scan.sh' } else { echo 'skip the scan for merge' }
64 }
65 }
66 }
67
68 stage('Prepare Test Image') {
69 steps {
70 script {
71 // Use shared test image from registry; no local build needed
72 sh "docker pull ${env.TEST_IMAGE} || true"
73 }
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('Linting Tests') {
85 sh """
86 docker run --rm ${common} \
87 ${env.TEST_IMAGE} \
88 /tests/devops-stages/stage-lint.sh
89 """
90 }
91
92 stage('Unit Tests') {
93 sh """
94 docker run --rm ${common} \
95 ${env.TEST_IMAGE} \
96 /tests/devops-stages/stage-test.sh
97 """
caviedesje9ea7a42026-02-26 12:47:18 +010098 if (fileExists('coverage.xml')) {
99 recordCoverage tools: [[
100 parser: 'COBERTURA',
101 pattern: 'coverage.xml'
102 ]], sourceDirectories: []
103 }
104
105 if (fileExists('nosetests.xml')) {
106 junit 'nosetests.xml'
107 }
caviedesj4ab749c2026-01-08 18:06:21 +0100108 }
109
110 stage('Changelog') {
111 sh 'mkdir -p changelog'
112 sh """
113 docker run --rm ${common} \
114 ${env.TEST_IMAGE} \
caviedesj56053962026-02-16 10:24:13 +0100115 sh -c 'devops/tools/generatechangelog-pipeline.sh > /tests/changelog/changelog-${MDG}.html'
caviedesj4ab749c2026-01-08 18:06:21 +0100116 """
117 }
118 }
119 }
120 }
121 }
122
123 post {
124 always {
125 // cleanWs()
126 deleteDir()
127 }
128 }
129}