| /* |
| 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, either express or |
| implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| */ |
| |
| pipeline { |
| 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') |
| } |
| environment { |
| MDG = "${params.GERRIT_PROJECT?.contains('/') ? params.GERRIT_PROJECT.split('/')[1] : params.GERRIT_PROJECT}" |
| TEST_IMAGE = 'opensourcemano/tox-osm:19.0' |
| } |
| 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" |
| } |
| } |
| } |
| |
| 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() |
| } |
| } |
| } |