From 4ab749c036e60b962321b137b962ca3272e56381 Mon Sep 17 00:00:00 2001 From: caviedesj Date: Thu, 8 Jan 2026 18:06:21 +0100 Subject: [PATCH] Feature 11077. Self-contained repos: new Jenkins pipeline Change-Id: I2050048125d996f3b8e8d91a07c3300a1a054bef Signed-off-by: caviedesj --- Jenkinsfile.new | 130 ++++++++++++++++++++++++++++++++---- devops-stages/stage-lint.sh | 18 +++++ devops-stages/stage-test.sh | 2 +- 3 files changed, 135 insertions(+), 15 deletions(-) create mode 100755 devops-stages/stage-lint.sh diff --git a/Jenkinsfile.new b/Jenkinsfile.new index 1161537..398a825 100644 --- a/Jenkinsfile.new +++ b/Jenkinsfile.new @@ -13,22 +13,124 @@ limitations under the License. */ +def DEFAULT_MODULE_NAME = 'im' + pipeline { - agent none - parameters { - string(defaultValue: env.GERRIT_BRANCH, description: '', name: 'GERRIT_BRANCH') - string(defaultValue: 'osm/IM', description: '', name: 'GERRIT_PROJECT') - string(defaultValue: env.GERRIT_REFSPEC, description: '', name: 'GERRIT_REFSPEC') - string(defaultValue: env.GERRIT_PATCHSET_REVISION, description: '', name: 'GERRIT_PATCHSET_REVISION') - string(defaultValue: 'https://osm.etsi.org/gerrit', description: '', name: 'PROJECT_URL_PREFIX') + agent { label 'pool' } + options { disableConcurrentBuilds() } + parameters { + // Core Gerrit / multibranch inputs + string(name: 'GERRIT_BRANCH', defaultValue: env.BRANCH_NAME ?: 'master', description: '') + string(name: 'GERRIT_PROJECT', defaultValue: 'osm/im', description: '') + string(name: 'GERRIT_REFSPEC', defaultValue: env.GERRIT_REFSPEC ?: '', description: '') + string(name: 'GERRIT_PATCHSET_REVISION', defaultValue: env.GERRIT_PATCHSET_REVISION ?: '', description: '') + string(name: 'PROJECT_URL_PREFIX', defaultValue: 'https://osm.etsi.org/gerrit', description: '') + string(name: 'DOCKER_ARGS', defaultValue: '', description: 'Extra docker args for docker run') + + // E2E test parameters + string(name: 'OPENSTACK_BASE_IMAGE', defaultValue: 'ubuntu22.04', description: '') + string(name: 'OPENSTACK_OSM_FLAVOR', defaultValue: 'osm.sanity', description: '') + + booleanParam(name: 'DO_INSTALL', defaultValue: true, description: '') + booleanParam(name: 'DO_ROBOT', defaultValue: true, description: '') + string(name: 'MODULE_NAME', defaultValue: 'IM', description: 'Name of the module under test') + + booleanParam(name: 'SAVE_CONTAINER_ON_FAIL', defaultValue: false, description: '') + booleanParam(name: 'SAVE_CONTAINER_ON_PASS', defaultValue: false, description: '') + } + environment { + MDG = "${params.GERRIT_PROJECT?.contains('/') ? params.GERRIT_PROJECT.split('/')[1] : params.GERRIT_PROJECT}" + CONTAINER_NAME = "${params.GERRIT_PROJECT}-${params.GERRIT_BRANCH}".toLowerCase() + TEST_IMAGE = 'overdrive3000/tox-osm:v1.6' + DOCKER_REGISTRY = 'osm.etsi.org:5050/devops/cicd/' + } + stages { + stage('Prepare') { steps { sh 'env' } } + + stage('Checkout') { + steps { + checkout scm + script { + sh "git fetch --tags" + if (params.GERRIT_REFSPEC?.trim()) { sh "git fetch origin ${params.GERRIT_REFSPEC}" } + if (params.GERRIT_PATCHSET_REVISION?.trim()) { sh "git checkout -f ${params.GERRIT_PATCHSET_REVISION}" } + sh "sudo git clean -dfx || git clean -dfx" + } + } + } + + stage('Clone devops (central)') { + steps { + dir('devops') { + sh "git init ." + sh "git remote remove origin || true" + sh "git remote add origin ${params.PROJECT_URL_PREFIX}/osm/devops" + sh "git fetch --depth=1 origin ${params.GERRIT_BRANCH}" + sh "git checkout -f FETCH_HEAD" + } + } + } + + stage('License Scan') { + steps { + script { + def isMergeJob = env.JOB_NAME?.contains('merge') + if (!isMergeJob) { sh 'devops/tools/license_scan.sh' } else { echo 'skip the scan for merge' } + } + } + } + + stage('Prepare Test Image') { + steps { + script { + // Use shared test image from registry; no local build needed + sh "docker pull ${env.TEST_IMAGE} || true" + } + } } - stages { - stage('TEST') { - agent { label 'system' } - steps { - echo "HELLO" - } + + stage('Tests') { + steps { + script { + def UID = sh(returnStdout: true, script: 'id -u').trim() + def GID = sh(returnStdout: true, script: 'id -g').trim() + def common = "-v ${env.WORKSPACE}:/tests -e UID=${UID} -e GID=${GID} " + (params.DOCKER_ARGS ?: '') + + stage('Linting Tests') { + sh """ + docker run --rm ${common} \ + ${env.TEST_IMAGE} \ + /tests/devops-stages/stage-lint.sh + """ + } + + stage('Unit Tests') { + sh """ + docker run --rm ${common} \ + ${env.TEST_IMAGE} \ + /tests/devops-stages/stage-test.sh + """ + if (fileExists('coverage.xml')) { cobertura coberturaReportFile: 'coverage.xml' } + if (fileExists('nosetests.xml')) { junit 'nosetests.xml' } + } + + stage('Changelog') { + sh 'mkdir -p changelog' + sh """ + docker run --rm ${common} \ + ${env.TEST_IMAGE} \ + /bin/sh -lc 'devops/tools/generatechangelog-pipeline.sh > /tests/changelog/changelog-${MDG}.html' + """ + } } + } } -} + } + post { + always { + // cleanWs() + deleteDir() + } + } +} \ No newline at end of file diff --git a/devops-stages/stage-lint.sh b/devops-stages/stage-lint.sh new file mode 100755 index 0000000..268652d --- /dev/null +++ b/devops-stages/stage-lint.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +echo "Launching tox" +# TOX_PARALLEL_NO_SPINNER=1 tox --parallel=auto -e black,flake8,pylint,safety +echo "DONE" diff --git a/devops-stages/stage-test.sh b/devops-stages/stage-test.sh index eee57ff..b2df907 100755 --- a/devops-stages/stage-test.sh +++ b/devops-stages/stage-test.sh @@ -18,4 +18,4 @@ echo "Launching tox" TOX_PARALLEL_NO_SPINNER=1 tox --parallel=auto - +# TOX_PARALLEL_NO_SPINNER=1 tox --parallel=auto -e cover \ No newline at end of file -- 2.25.1