blob: 48293b2cb9f46028e84bfb532a5678223fa88958 [file] [log] [blame]
garciadeblaseb7d85d2025-12-23 22:56:29 +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
caviedesjf186ccd2026-01-09 11:59:12 +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/common', 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')
caviedesjf186ccd2026-01-09 11:59:12 +010027 }
28 environment {
29 MDG = "${params.GERRIT_PROJECT?.contains('/') ? params.GERRIT_PROJECT.split('/')[1] : params.GERRIT_PROJECT}"
30 CONTAINER_NAME = "${params.GERRIT_PROJECT}-${params.GERRIT_BRANCH}".toLowerCase()
caviedesj520bd182026-02-12 19:04:38 +010031 TEST_IMAGE = 'opensourcemano/tox-osm:19.0'
caviedesjf186ccd2026-01-09 11:59:12 +010032 DOCKER_REGISTRY = 'osm.etsi.org:5050/devops/cicd/'
33 }
34 stages {
35 stage('Prepare') { steps { sh 'env' } }
36
37 stage('Checkout') {
38 steps {
39 checkout scm
40 script {
41 sh "git fetch --tags"
42 if (params.GERRIT_REFSPEC?.trim()) { sh "git fetch origin ${params.GERRIT_REFSPEC}" }
43 if (params.GERRIT_PATCHSET_REVISION?.trim()) { sh "git checkout -f ${params.GERRIT_PATCHSET_REVISION}" }
44 sh "sudo git clean -dfx || git clean -dfx"
45 }
46 }
47 }
48
49 stage('Clone devops (central)') {
50 steps {
51 dir('devops') {
52 sh "git init ."
53 sh "git remote remove origin || true"
54 sh "git remote add origin ${params.PROJECT_URL_PREFIX}/osm/devops"
55 sh "git fetch --depth=1 origin ${params.GERRIT_BRANCH}"
56 sh "git checkout -f FETCH_HEAD"
57 }
58 }
59 }
60
61 stage('License Scan') {
62 steps {
63 script {
64 def isMergeJob = env.JOB_NAME?.contains('merge')
65 if (!isMergeJob) { sh 'devops/tools/license_scan.sh' } else { echo 'skip the scan for merge' }
66 }
67 }
68 }
69
70 stage('Prepare Test Image') {
71 steps {
72 script {
73 // Use shared test image from registry; no local build needed
74 sh "docker pull ${env.TEST_IMAGE} || true"
75 }
76 }
77 }
78
79 stage('Tests') {
80 steps {
81 script {
82 def UID = sh(returnStdout: true, script: 'id -u').trim()
83 def GID = sh(returnStdout: true, script: 'id -g').trim()
84 def common = "-v ${env.WORKSPACE}:/tests -e UID=${UID} -e GID=${GID} " + (params.DOCKER_ARGS ?: '')
85
86 stage('Linting Tests') {
87 sh """
88 docker run --rm ${common} \
89 ${env.TEST_IMAGE} \
90 /tests/devops-stages/stage-lint.sh
91 """
92 }
93
94 stage('Unit Tests') {
95 sh """
96 docker run --rm ${common} \
97 ${env.TEST_IMAGE} \
98 /tests/devops-stages/stage-test.sh
99 """
100 if (fileExists('coverage.xml')) { cobertura coberturaReportFile: 'coverage.xml' }
101 if (fileExists('nosetests.xml')) { junit 'nosetests.xml' }
102 }
103
104 stage('Changelog') {
105 sh 'mkdir -p changelog'
106 sh """
107 docker run --rm ${common} \
108 ${env.TEST_IMAGE} \
garciadeblas141f19e2026-02-16 11:22:42 +0100109 sh -c 'devops/tools/generatechangelog-pipeline.sh > /tests/changelog/changelog-${MDG}.html'
caviedesjf186ccd2026-01-09 11:59:12 +0100110 """
111 }
112 }
113 }
114 }
115 }
116
117 post {
118 always {
119 // cleanWs()
120 deleteDir()
121 }
122 }
garciadeblas141f19e2026-02-16 11:22:42 +0100123}