Fix 11077. Self-contained repos: new Jenkins pipeline 46/15646/3
authorcaviedesj <juancamilo.caviedesvalencia.ext@telefonica.com>
Fri, 9 Jan 2026 10:59:12 +0000 (11:59 +0100)
committercaviedesj <juancamilo.caviedesvalencia.ext@telefonica.com>
Fri, 9 Jan 2026 11:42:26 +0000 (12:42 +0100)
Change-Id: I422e861d2015e2c4937b4b1e720932d153656b3d
Signed-off-by: caviedesj <juancamilo.caviedesvalencia.ext@telefonica.com>
Jenkinsfile.new
devops-stages/stage-lint.sh [new file with mode: 0755]
devops-stages/stage-test.sh

index 652c1eb..35154c4 100644 (file)
   limitations under the License.
 */
 
+def DEFAULT_MODULE_NAME = 'common'
+
 pipeline {
-    agent none
-    parameters {
-        string(defaultValue: env.GERRIT_BRANCH, description: '', name: 'GERRIT_BRANCH')
-        string(defaultValue: 'osm/common', 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/common', 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: 'common', 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 (executable)
index 0000000..268652d
--- /dev/null
@@ -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"
index c9360d5..fe6f09c 100755 (executable)
@@ -13,6 +13,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-echo Launching tox
+echo "Launching tox"
 TOX_PARALLEL_NO_SPINNER=1 tox --parallel=auto
-
+# TOX_PARALLEL_NO_SPINNER=1 tox --parallel=auto -e cover