|
1 | 1 | #!/usr/bin/env groovy |
2 | 2 |
|
3 | 3 | def doDebugBuild(coverageEnabled=false) { |
| 4 | + def dPullOrBuild = load ".jenkinsci/docker-pull-or-build.groovy" |
| 5 | + def manifest = load ".jenkinsci/docker-manifest.groovy" |
| 6 | + def pCommit = load ".jenkinsci/previous-commit.groovy" |
4 | 7 | def parallelism = params.PARALLELISM |
| 8 | + def platform = sh(script: 'uname -m', returnStdout: true).trim() |
| 9 | + def previousCommit = pCommit.previousCommitOrCurrent() |
5 | 10 | // params are always null unless job is started |
6 | 11 | // this is the case for the FIRST build only. |
7 | 12 | // So just set this to same value as default. |
8 | 13 | // This is a known bug. See https://issues.jenkins-ci.org/browse/JENKINS-41929 |
9 | | - if (parallelism == null) { |
| 14 | + if (!parallelism) { |
10 | 15 | parallelism = 4 |
11 | 16 | } |
12 | | - if ("arm7" in env.NODE_NAME) { |
| 17 | + if (env.NODE_NAME.contains('arm7')) { |
13 | 18 | parallelism = 1 |
14 | 19 | } |
15 | 20 | sh "docker network create ${env.IROHA_NETWORK}" |
| 21 | + def iC = dPullOrBuild.dockerPullOrUpdate("${platform}-develop-build", |
| 22 | + "${env.GIT_RAW_BASE_URL}/${env.GIT_COMMIT}/docker/develop/Dockerfile", |
| 23 | + "${env.GIT_RAW_BASE_URL}/${previousCommit}/docker/develop/Dockerfile", |
| 24 | + "${env.GIT_RAW_BASE_URL}/develop/docker/develop/Dockerfile", |
| 25 | + ['PARALLELISM': parallelism]) |
16 | 26 |
|
17 | | - docker.image('postgres:9.5').run("" |
| 27 | + if (GIT_LOCAL_BRANCH == 'develop' && manifest.manifestSupportEnabled()) { |
| 28 | + manifest.manifestCreate("${DOCKER_REGISTRY_BASENAME}:develop-build", |
| 29 | + ["${DOCKER_REGISTRY_BASENAME}:x86_64-develop-build", |
| 30 | + "${DOCKER_REGISTRY_BASENAME}:armv7l-develop-build", |
| 31 | + "${DOCKER_REGISTRY_BASENAME}:aarch64-develop-build"]) |
| 32 | + manifest.manifestAnnotate("${DOCKER_REGISTRY_BASENAME}:develop-build", |
| 33 | + [ |
| 34 | + [manifest: "${DOCKER_REGISTRY_BASENAME}:x86_64-develop-build", |
| 35 | + arch: 'amd64', os: 'linux', osfeatures: [], variant: ''], |
| 36 | + [manifest: "${DOCKER_REGISTRY_BASENAME}:armv7l-develop-build", |
| 37 | + arch: 'arm', os: 'linux', osfeatures: [], variant: 'v7'], |
| 38 | + [manifest: "${DOCKER_REGISTRY_BASENAME}:aarch64-develop-build", |
| 39 | + arch: 'arm64', os: 'linux', osfeatures: [], variant: ''] |
| 40 | + ]) |
| 41 | + withCredentials([usernamePassword(credentialsId: 'docker-hub-credentials', usernameVariable: 'login', passwordVariable: 'password')]) { |
| 42 | + manifest.manifestPush("${DOCKER_REGISTRY_BASENAME}:develop-build", login, password) |
| 43 | + } |
| 44 | + } |
| 45 | + docker.image('postgres:9.5').withRun("" |
18 | 46 | + " -e POSTGRES_USER=${env.IROHA_POSTGRES_USER}" |
19 | 47 | + " -e POSTGRES_PASSWORD=${env.IROHA_POSTGRES_PASSWORD}" |
20 | 48 | + " --name ${env.IROHA_POSTGRES_HOST}" |
21 | | - + " --network=${env.IROHA_NETWORK}") |
22 | | - |
23 | | - def platform = sh(script: 'uname -m', returnStdout: true).trim() |
24 | | - sh "curl -L -o /tmp/${env.GIT_COMMIT}/Dockerfile --create-dirs https://raw.githubusercontent.com/hyperledger/iroha/${env.GIT_COMMIT}/docker/develop/${platform}/Dockerfile" |
25 | | - // pull docker image in case we don't have one |
26 | | - // speeds up consequent image builds as we simply tag them |
27 | | - sh "docker pull ${DOCKER_BASE_IMAGE_DEVELOP}" |
28 | | - if (env.BRANCH_NAME == 'develop') { |
29 | | - iC = docker.build("hyperledger/iroha:${GIT_COMMIT}-${BUILD_NUMBER}", "--build-arg PARALLELISM=${parallelism} -f /tmp/${env.GIT_COMMIT}/Dockerfile /tmp/${env.GIT_COMMIT}") |
30 | | - docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials') { |
31 | | - iC.push("${platform}-develop") |
32 | | - } |
33 | | - } |
34 | | - else { |
35 | | - iC = docker.build("hyperledger/iroha-workflow:${GIT_COMMIT}-${BUILD_NUMBER}", "-f /tmp/${env.GIT_COMMIT}/Dockerfile /tmp/${env.GIT_COMMIT} --build-arg PARALLELISM=${parallelism}") |
36 | | - } |
37 | | - iC.inside("" |
38 | | - + " -e IROHA_POSTGRES_HOST=${env.IROHA_POSTGRES_HOST}" |
39 | | - + " -e IROHA_POSTGRES_PORT=${env.IROHA_POSTGRES_PORT}" |
40 | | - + " -e IROHA_POSTGRES_USER=${env.IROHA_POSTGRES_USER}" |
41 | | - + " -e IROHA_POSTGRES_PASSWORD=${env.IROHA_POSTGRES_PASSWORD}" |
42 | | - + " --network=${env.IROHA_NETWORK}" |
43 | | - + " -v /var/jenkins/ccache:${CCACHE_DIR}") { |
44 | | - |
45 | | - def scmVars = checkout scm |
46 | | - def cmakeOptions = "" |
47 | | - if ( coverageEnabled ) { |
48 | | - cmakeOptions = " -DCOVERAGE=ON " |
49 | | - } |
50 | | - env.IROHA_VERSION = "0x${scmVars.GIT_COMMIT}" |
51 | | - env.IROHA_HOME = "/opt/iroha" |
52 | | - env.IROHA_BUILD = "${env.IROHA_HOME}/build" |
| 49 | + + " --network=${env.IROHA_NETWORK}") { |
| 50 | + iC.inside("" |
| 51 | + + " -e IROHA_POSTGRES_HOST=${env.IROHA_POSTGRES_HOST}" |
| 52 | + + " -e IROHA_POSTGRES_PORT=${env.IROHA_POSTGRES_PORT}" |
| 53 | + + " -e IROHA_POSTGRES_USER=${env.IROHA_POSTGRES_USER}" |
| 54 | + + " -e IROHA_POSTGRES_PASSWORD=${env.IROHA_POSTGRES_PASSWORD}" |
| 55 | + + " --network=${env.IROHA_NETWORK}" |
| 56 | + + " -v /var/jenkins/ccache:${CCACHE_DIR}" |
| 57 | + + " -v /tmp/${GIT_COMMIT}-${BUILD_NUMBER}:/tmp/${GIT_COMMIT}") { |
53 | 58 |
|
54 | | - sh """ |
55 | | - ccache --version |
56 | | - ccache --show-stats |
57 | | - ccache --zero-stats |
58 | | - ccache --max-size=5G |
59 | | - """ |
60 | | - sh """ |
61 | | - cmake \ |
62 | | - -DTESTING=ON \ |
63 | | - -H. \ |
64 | | - -Bbuild \ |
65 | | - -DCMAKE_BUILD_TYPE=Debug \ |
66 | | - -DIROHA_VERSION=${env.IROHA_VERSION} \ |
67 | | - ${cmakeOptions} |
68 | | - """ |
69 | | - sh "cmake --build build -- -j${parallelism}" |
70 | | - sh "ccache --show-stats" |
71 | | - if ( coverageEnabled ) { |
72 | | - sh "cmake --build build --target coverage.init.info" |
73 | | - } |
74 | | - def testExitCode = sh(script: 'cmake --build build --target test', returnStatus: true) |
75 | | - if (testExitCode != 0) { |
76 | | - currentBuild.result = "UNSTABLE" |
77 | | - } |
78 | | - if ( coverageEnabled ) { |
79 | | - sh "cmake --build build --target cppcheck" |
80 | | - // Sonar |
81 | | - if (env.CHANGE_ID != null) { |
82 | | - sh """ |
83 | | - sonar-scanner \ |
84 | | - -Dsonar.github.disableInlineComments \ |
85 | | - -Dsonar.github.repository='hyperledger/iroha' \ |
86 | | - -Dsonar.analysis.mode=preview \ |
87 | | - -Dsonar.login=${SONAR_TOKEN} \ |
88 | | - -Dsonar.projectVersion=${BUILD_TAG} \ |
89 | | - -Dsonar.github.oauth=${SORABOT_TOKEN} \ |
90 | | - -Dsonar.github.pullRequest=${CHANGE_ID} |
91 | | - """ |
| 59 | + def scmVars = checkout scm |
| 60 | + def cmakeOptions = "" |
| 61 | + if ( coverageEnabled ) { |
| 62 | + cmakeOptions = " -DCOVERAGE=ON " |
92 | 63 | } |
| 64 | + env.IROHA_VERSION = "0x${scmVars.GIT_COMMIT}" |
| 65 | + env.IROHA_HOME = "/opt/iroha" |
| 66 | + env.IROHA_BUILD = "${env.IROHA_HOME}/build" |
93 | 67 |
|
94 | | - sh "cmake --build build --target coverage.info" |
95 | | - sh "python /tmp/lcov_cobertura.py build/reports/coverage.info -o build/reports/coverage.xml" |
96 | | - cobertura autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/build/reports/coverage.xml', conditionalCoverageTargets: '75, 50, 0', failUnhealthy: false, failUnstable: false, lineCoverageTargets: '75, 50, 0', maxNumberOfBuilds: 50, methodCoverageTargets: '75, 50, 0', onlyStable: false, zoomCoverageChart: false |
97 | | - } |
98 | | - |
99 | | - // TODO: replace with upload to artifactory server |
100 | | - // develop branch only |
101 | | - if ( env.BRANCH_NAME == "develop" ) { |
102 | | - //archive(includes: 'build/bin/,compile_commands.json') |
| 68 | + sh """ |
| 69 | + ccache --version |
| 70 | + ccache --show-stats |
| 71 | + ccache --zero-stats |
| 72 | + ccache --max-size=5G |
| 73 | + """ |
| 74 | + sh """ |
| 75 | + cmake \ |
| 76 | + -DTESTING=ON \ |
| 77 | + -H. \ |
| 78 | + -Bbuild \ |
| 79 | + -DCMAKE_BUILD_TYPE=Debug \ |
| 80 | + -DIROHA_VERSION=${env.IROHA_VERSION} \ |
| 81 | + ${cmakeOptions} |
| 82 | + """ |
| 83 | + sh "cmake --build build -- -j${parallelism}" |
| 84 | + sh "ccache --show-stats" |
| 85 | + if ( coverageEnabled ) { |
| 86 | + sh "cmake --build build --target coverage.init.info" |
| 87 | + } |
| 88 | + def testExitCode = sh(script: 'CTEST_OUTPUT_ON_FAILURE=1 cmake --build build --target test', returnStatus: true) |
| 89 | + if (testExitCode != 0) { |
| 90 | + currentBuild.result = "UNSTABLE" |
| 91 | + } |
| 92 | + if ( coverageEnabled ) { |
| 93 | + sh "cmake --build build --target cppcheck" |
| 94 | + // Sonar |
| 95 | + if (env.CHANGE_ID != null) { |
| 96 | + sh """ |
| 97 | + sonar-scanner \ |
| 98 | + -Dsonar.github.disableInlineComments \ |
| 99 | + -Dsonar.github.repository='${DOCKER_REGISTRY_BASENAME}' \ |
| 100 | + -Dsonar.analysis.mode=preview \ |
| 101 | + -Dsonar.login=${SONAR_TOKEN} \ |
| 102 | + -Dsonar.projectVersion=${BUILD_TAG} \ |
| 103 | + -Dsonar.github.oauth=${SORABOT_TOKEN} \ |
| 104 | + -Dsonar.github.pullRequest=${CHANGE_ID} |
| 105 | + """ |
| 106 | + } |
| 107 | + sh "cmake --build build --target coverage.info" |
| 108 | + sh "python /tmp/lcov_cobertura.py build/reports/coverage.info -o build/reports/coverage.xml" |
| 109 | + cobertura autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/build/reports/coverage.xml', conditionalCoverageTargets: '75, 50, 0', failUnhealthy: false, failUnstable: false, lineCoverageTargets: '75, 50, 0', maxNumberOfBuilds: 50, methodCoverageTargets: '75, 50, 0', onlyStable: false, zoomCoverageChart: false |
| 110 | + } |
103 | 111 | } |
104 | 112 | } |
105 | 113 | } |
| 114 | + |
106 | 115 | return this |
0 commit comments