|
| 1 | +#!/usr/bin/env groovy |
| 2 | +/** |
| 3 | + * Copyright Soramitsu Co., Ltd. All Rights Reserved. |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +// |
| 8 | +// Linux Build steps |
| 9 | +// |
| 10 | + |
| 11 | +def dockerManifestPush(dockerImageObj, String dockerTag, environment) { |
| 12 | + def manifest = load ".jenkinsci-new/utils/docker-manifest.groovy" |
| 13 | + withEnv(environment) { |
| 14 | + if (manifest.manifestSupportEnabled()) { |
| 15 | + manifest.manifestCreate("${env.DOCKER_REGISTRY_BASENAME}:${dockerTag}", |
| 16 | + ["${env.DOCKER_REGISTRY_BASENAME}:x86_64-${dockerTag}"]) |
| 17 | + manifest.manifestAnnotate("${env.DOCKER_REGISTRY_BASENAME}:${dockerTag}", |
| 18 | + [ |
| 19 | + [manifest: "${env.DOCKER_REGISTRY_BASENAME}:x86_64-${dockerTag}", |
| 20 | + arch: 'amd64', os: 'linux', osfeatures: [], variant: ''], |
| 21 | + ]) |
| 22 | + withCredentials([usernamePassword(credentialsId: 'docker-hub-credentials', usernameVariable: 'login', passwordVariable: 'password')]) { |
| 23 | + manifest.manifestPush("${env.DOCKER_REGISTRY_BASENAME}:${dockerTag}", login, password) |
| 24 | + } |
| 25 | + } |
| 26 | + else { |
| 27 | + echo('[WARNING] Docker CLI does not support manifest management features. Manifest will not be updated') |
| 28 | + } |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +def testSteps(String buildDir, List environment, String testList) { |
| 33 | + withEnv(environment) { |
| 34 | + sh "cd ${buildDir}; ctest --output-on-failure --no-compress-output --tests-regex '${testList}' --test-action Test || true" |
| 35 | + sh """ python .jenkinsci-new/helpers/platform_tag.py "Linux \$(uname -m)" \$(ls ${buildDir}/Testing/*/Test.xml) """ |
| 36 | + // Mark build as UNSTABLE if there are any failed tests (threshold <100%) |
| 37 | + xunit testTimeMargin: '3000', thresholdMode: 2, thresholds: [passed(unstableThreshold: '100')], \ |
| 38 | + tools: [CTest(deleteOutputFiles: true, failIfNotNew: false, \ |
| 39 | + pattern: "${buildDir}/Testing/**/Test.xml", skipNoTestFiles: false, stopProcessingIfError: true)] |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +def buildSteps(int parallelism, List compilerVersions, String build_type, boolean specialBranch, boolean coverage, |
| 44 | + boolean testing, String testList, boolean cppcheck, boolean sonar, boolean docs, boolean packagebuild, boolean sanitize, boolean fuzzing, List environment) { |
| 45 | + withEnv(environment) { |
| 46 | + scmVars = checkout scm |
| 47 | + def build = load '.jenkinsci-new/build.groovy' |
| 48 | + def vars = load ".jenkinsci-new/utils/vars.groovy" |
| 49 | + def utils = load ".jenkinsci-new/utils/utils.groovy" |
| 50 | + def dockerUtils = load ".jenkinsci-new/utils/docker-pull-or-build.groovy" |
| 51 | + def doxygen = load ".jenkinsci-new/utils/doxygen.groovy" |
| 52 | + buildDir = 'build' |
| 53 | + compilers = vars.compilerMapping() |
| 54 | + cmakeBooleanOption = [ (true): 'ON', (false): 'OFF' ] |
| 55 | + platform = sh(script: 'uname -m', returnStdout: true).trim() |
| 56 | + cmakeBuildOptions = "" |
| 57 | + cmakeOptions = "" |
| 58 | + if (packagebuild){ |
| 59 | + cmakeBuildOptions = " --target package " |
| 60 | + } |
| 61 | + if (sanitize){ |
| 62 | + cmakeOptions += " -DSANITIZE='address;leak' " |
| 63 | + } |
| 64 | + |
| 65 | + // Create postgres |
| 66 | + // enable prepared transactions so that 2 phase commit works |
| 67 | + // we set it to 100 as a safe value |
| 68 | + sh """#!/bin/bash -xe |
| 69 | + if [ ! "\$(docker ps -q -f name=${env.IROHA_POSTGRES_HOST})" ]; then |
| 70 | + docker network create ${env.IROHA_NETWORK} |
| 71 | + docker run -td -e POSTGRES_USER=${env.IROHA_POSTGRES_USER} \ |
| 72 | + -e POSTGRES_PASSWORD=${env.IROHA_POSTGRES_PASSWORD} --name ${env.IROHA_POSTGRES_HOST} \ |
| 73 | + --network=${env.IROHA_NETWORK} postgres:9.5 -c 'max_prepared_transactions=100' |
| 74 | + fi |
| 75 | + """ |
| 76 | + |
| 77 | + iC = dockerUtils.dockerPullOrBuild("${platform}-develop-build", |
| 78 | + "${env.GIT_RAW_BASE_URL}/${scmVars.GIT_COMMIT}/docker/develop/Dockerfile", |
| 79 | + "${env.GIT_RAW_BASE_URL}/${utils.previousCommitOrCurrent(scmVars)}/docker/develop/Dockerfile", |
| 80 | + "${env.GIT_RAW_BASE_URL}/develop/docker/develop/Dockerfile", |
| 81 | + scmVars, |
| 82 | + environment, |
| 83 | + ['PARALLELISM': parallelism]) |
| 84 | + |
| 85 | + iC.inside("" |
| 86 | + + " -e IROHA_POSTGRES_HOST=${env.IROHA_POSTGRES_HOST}" |
| 87 | + + " -e IROHA_POSTGRES_PORT=${env.IROHA_POSTGRES_PORT}" |
| 88 | + + " -e IROHA_POSTGRES_USER=${env.IROHA_POSTGRES_USER}" |
| 89 | + + " -e IROHA_POSTGRES_PASSWORD=${env.IROHA_POSTGRES_PASSWORD}" |
| 90 | + + " --network=${env.IROHA_NETWORK}" |
| 91 | + + " -v /var/jenkins/ccache:${env.CCACHE_DEBUG_DIR}") { |
| 92 | + utils.ccacheSetup(5) |
| 93 | + for (compiler in compilerVersions) { |
| 94 | + stage ("build ${compiler}"){ |
| 95 | + build.cmakeConfigure(buildDir, "-DCMAKE_CXX_COMPILER=${compilers[compiler]['cxx_compiler']} \ |
| 96 | + -DCMAKE_C_COMPILER=${compilers[compiler]['cc_compiler']} \ |
| 97 | + -DCMAKE_BUILD_TYPE=${build_type} \ |
| 98 | + -DCOVERAGE=${cmakeBooleanOption[coverage]} \ |
| 99 | + -DTESTING=${cmakeBooleanOption[testing]} \ |
| 100 | + -DFUZZING=${cmakeBooleanOption[fuzzing]} \ |
| 101 | + -DPACKAGE_DEB=${cmakeBooleanOption[packagebuild]} \ |
| 102 | + -DPACKAGE_TGZ=${cmakeBooleanOption[packagebuild]} ${cmakeOptions}") |
| 103 | + build.cmakeBuild(buildDir, cmakeBuildOptions, parallelism) |
| 104 | + } |
| 105 | + if (testing) { |
| 106 | + stage("Test ${compiler}") { |
| 107 | + coverage ? build.initialCoverage(buildDir) : echo('Skipping initial coverage...') |
| 108 | + testSteps(buildDir, environment, testList) |
| 109 | + coverage ? build.postCoverage(buildDir, '/tmp/lcov_cobertura.py') : echo('Skipping post coverage...') |
| 110 | + // We run coverage once, using the first compiler as it is enough |
| 111 | + coverage = false |
| 112 | + } |
| 113 | + } //end if |
| 114 | + } //end for |
| 115 | + stage("Analysis") { |
| 116 | + cppcheck ? build.cppCheck(buildDir, parallelism) : echo('Skipping Cppcheck...') |
| 117 | + sonar ? build.sonarScanner(scmVars, environment) : echo('Skipping Sonar Scanner...') |
| 118 | + } |
| 119 | + stage('Build docs'){ |
| 120 | + docs ? doxygen.doDoxygen(specialBranch, scmVars.GIT_LOCAL_BRANCH) : echo("Skipping Doxygen...") |
| 121 | + } |
| 122 | + } // end iC.inside |
| 123 | + stage ('Docker ManifestPush'){ |
| 124 | + if (specialBranch) { |
| 125 | + utils.dockerPush(iC, "${platform}-develop-build") |
| 126 | + dockerManifestPush(iC, "develop-build", environment) |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +def successPostSteps(scmVars, boolean packagePush, String dockerTag, List environment) { |
| 133 | + stage('Linux success PostSteps') { |
| 134 | + withEnv(environment) { |
| 135 | + if (packagePush) { |
| 136 | + def artifacts = load ".jenkinsci-new/artifacts.groovy" |
| 137 | + def utils = load ".jenkinsci-new/utils/utils.groovy" |
| 138 | + platform = sh(script: 'uname -m', returnStdout: true).trim() |
| 139 | + def commit = scmVars.GIT_COMMIT |
| 140 | + |
| 141 | + // if we use several compilers only the last compiler, used for the build, will be used for iroha.deb and iroha.tar.gz archives |
| 142 | + sh """ |
| 143 | + ls -lah ./build |
| 144 | + mv ./build/iroha-*.deb ./build/iroha.deb |
| 145 | + mv ./build/iroha-*.tar.gz ./build/iroha.tar.gz |
| 146 | + cp ./build/iroha.deb docker/release/iroha.deb |
| 147 | + mkdir -p build/artifacts |
| 148 | + mv ./build/iroha.deb ./build/iroha.tar.gz build/artifacts |
| 149 | + """ |
| 150 | + // publish docker |
| 151 | + iCRelease = docker.build("${env.DOCKER_REGISTRY_BASENAME}:${commit}-${env.BUILD_NUMBER}-release", "--no-cache -f docker/release/Dockerfile ${WORKSPACE}/docker/release") |
| 152 | + utils.dockerPush(iCRelease, "${platform}-${dockerTag}") |
| 153 | + dockerManifestPush(iCRelease, dockerTag, environment) |
| 154 | + sh "docker rmi ${iCRelease.id}" |
| 155 | + |
| 156 | + // publish packages |
| 157 | + filePaths = [ './build/artifacts/iroha.deb', './build/artifacts/iroha.tar.gz' ] |
| 158 | + artifacts.uploadArtifacts(filePaths, sprintf('/iroha/linux/%4$s/%1$s-%2$s-%3$s', [scmVars.GIT_LOCAL_BRANCH, sh(script: 'date "+%Y%m%d"', returnStdout: true).trim(), commit.substring(0,6), platform])) |
| 159 | + } else { |
| 160 | + archiveArtifacts artifacts: 'build/iroha*.tar.gz', allowEmptyArchive: true |
| 161 | + archiveArtifacts artifacts: 'build/iroha*.deb', allowEmptyArchive: true |
| 162 | + } |
| 163 | + } |
| 164 | + } |
| 165 | +} |
| 166 | + |
| 167 | +def alwaysPostSteps(List environment) { |
| 168 | + stage('Linux always PostSteps') { |
| 169 | + withEnv(environment) { |
| 170 | + sh "docker rm -f ${env.IROHA_POSTGRES_HOST} || true" |
| 171 | + sh "docker network rm ${env.IROHA_NETWORK}" |
| 172 | + cleanWs() |
| 173 | + } |
| 174 | + } |
| 175 | +} |
| 176 | + |
| 177 | +return this |
0 commit comments