X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=jenkins%2Fci-pipelines%2Fci_stage_2.groovy;h=5cad17b052af5d8eaf8b21d0941a89eb32b7d3b6;hb=b3ac0c2eb3a011766030c83929f1b859f2d1e24b;hp=68d221f1dc94270183b1b54a13a94cf215495614;hpb=49fd6e5620f31ab369fb79d328e10dfb6db38281;p=osm%2Fdevops.git diff --git a/jenkins/ci-pipelines/ci_stage_2.groovy b/jenkins/ci-pipelines/ci_stage_2.groovy index 68d221f1..5cad17b0 100644 --- a/jenkins/ci-pipelines/ci_stage_2.groovy +++ b/jenkins/ci-pipelines/ci_stage_2.groovy @@ -1,7 +1,7 @@ /* Copyright 2017 Sandvine * * All Rights Reserved. - * + * * 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 @@ -20,14 +20,15 @@ def project_checkout(url_prefix,project,refspec,revision) { // this is done automaticaly by the multibranch pipeline plugin // git url: "${url_prefix}/${project}" + sh "git fetch --tags" sh "git fetch origin ${refspec}" if (GERRIT_PATCHSET_REVISION.size() > 0 ) { sh "git checkout -f ${revision}" } } -def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,build_system,artifactory_server,docker_args="") { - println("build_system = ${build_system}") +def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifactory_server,docker_args="",do_stage_4=false) { + println("do_stage_3= ${do_stage_3}") ci_helper = load "devops/jenkins/ci-pipelines/ci_helper.groovy" stage('Prepare') { @@ -39,7 +40,12 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,build_system,arti } stage('License Scan') { + if (!JOB_NAME.contains('merge')) { sh "devops/tools/license_scan.sh" + } + else { + println("skip the scan for merge") + } } container_name = "${project}-${branch}".toLowerCase() @@ -55,28 +61,67 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,build_system,arti withDockerContainer(image: "${container_name}", args: docker_args) { stage('Test') { sh 'devops-stages/stage-test.sh' + if (fileExists('coverage.xml')) { + cobertura coberturaReportFile: 'coverage.xml' + } + if (fileExists('nosetests.xml')) { + junit 'nosetests.xml' + } } stage('Build') { sh(returnStdout:true, script: 'devops-stages/stage-build.sh').trim() } + stage('Archive') { + sh "mkdir -p changelog" + sh "devops/tools/generatechangelog-pipeline.sh > changelog/changelog-${mdg}.html" + sh(returnStdout:true, script: 'devops-stages/stage-archive.sh').trim() + ci_helper.archive(artifactory_server,mdg,branch,'untested') + } } - stage('Archive') { - sh(returnStdout:true, script: 'devops-stages/stage-archive.sh').trim() - ci_helper.archive(artifactory_server,mdg,branch,'untested') + if (fileExists('snap/snapcraft.yaml')) { + stage('Snap build') { + sh "docker pull snapcore/snapcraft:stable" + sh "sudo rm -rf ${WORKSPACE}/stage/ ${WORKSPACE}/parts/ ${WORKSPACE}/prime/ ${WORKSPACE}/*.snap" + sh "sudo snapcraft clean --use-lxd" + sh "snapcraft --use-lxd" + sh "mv ${WORKSPACE}/${mdg}_*.snap ${WORKSPACE}/${mdg}.snap" + sh "sudo rm -rf ${WORKSPACE}/stage/ ${WORKSPACE}/parts/ ${WORKSPACE}/prime/" + + REV="" + if ( !JOB_NAME.contains('merge') ) { + REV="/"+"${GERRIT_REFSPEC}".replaceAll('/','-') + } + channel="latest" + if (BRANCH_NAME.startsWith("v")) { + channel=BRANCH_NAME.substring(1) + } else if (BRANCH_NAME!="master") { + REV="/"+BRANCH_NAME+REV.replaceAll('/','-') + } + + sh "sudo docker run -v ~/.snapcraft:/snapcraft -v ${WORKSPACE}:/build " + + "-w /build snapcore/snapcraft:stable /bin/bash -c " + + "\"snapcraft login --with /snapcraft/config ; snapcraft push --release=${channel}/edge${REV} ${mdg}.snap\"" + sh "sudo rm -rf ${WORKSPACE}/*.snap" + } } - if ( build_system ) { + if ( do_stage_3 ) { stage('Build System') { def downstream_params_stage_3 = [ string(name: 'GERRIT_BRANCH', value: "${branch}"), string(name: 'UPSTREAM_JOB_NAME', value: "${JOB_NAME}" ), string(name: 'UPSTREAM_JOB_NUMBER', value: "${BUILD_NUMBER}" ), + booleanParam(name: 'DO_STAGE_4', value: do_stage_4 ) ] + stage_3_job = "osm-stage_3" + if ( JOB_NAME.contains('merge') ) { + stage_3_job += '-merge' + } - // callout to stage_3. This is the system build - result = build job: "osm-stage_3/${branch}", parameters: downstream_params_stage_3, propagate: true + // callout to stage_3. This is the system build + result = build job: "${stage_3_job}/${branch}", parameters: downstream_params_stage_3, propagate: true if (result.getResult() != 'SUCCESS') { project = result.getProjectName() build = result.getNumber()