github.com/adecaro/fabric-ca@v2.0.0-alpha+incompatible/Jenkinsfile (about) 1 #!groovy 2 3 // Copyright IBM Corp All Rights Reserved 4 // 5 // SPDX-License-Identifier: Apache-2.0 6 // 7 8 // Jenkinfile will get triggered on verify and merge jobs and run basicChecks, docsBuild as a pre-tests 9 // and call unitTests, fvtTests to run on parallel build nodes. 10 // along with above mentioned tests, merge job also triggers e2e tests (fabcar, e2e_sdk_node & e2e_sdk_java) 11 12 @Library("fabric-ci-lib") _ 13 // global shared library from ci-management repository 14 // https://github.com/hyperledger/ci-management/tree/master/vars (Global Shared scripts) 15 timestamps { // set the timestamps on the jenkins console 16 timeout(120) { // Build timeout set to 120 mins 17 node ('hyp-x') { // trigger jobs on x86_64 builds nodes 18 def DOC_CHANGE 19 def CODE_CHANGE 20 def failure_stage = "none" 21 env.MARCH = sh(returnStdout: true, script: "uname -m | sed 's/x86_64/amd64/g'").trim() 22 buildStages() // call buildStages 23 } // end node block 24 } // end timeout block 25 } // end timestamps block 26 27 def buildStages() { 28 try { 29 // LF team has to install the newer version in Jenkins global config 30 // Send an email to helpdesk@hyperledger.org to add newer version 31 def nodeHome = tool 'nodejs-8.14.0' 32 def ROOTDIR = pwd() 33 stage('Clean Environment') { 34 // delete working directory 35 deleteDir() 36 // Clean build environment before start the build 37 fabBuildLibrary.cleanupEnv() 38 // Display jenkins environment details 39 fabBuildLibrary.envOutput() 40 } 41 42 stage('Checkout SCM') { 43 // Clone changes from gerrit 44 fabBuildLibrary.cloneRefSpec('fabric-ca') 45 dir("$ROOTDIR/$BASE_DIR") { 46 DOC_CHANGE = sh(returnStdout: true, script: "git diff-tree --no-commit-id --name-only -r HEAD | egrep '.md\$|.rst\$|.txt\$|conf.py\$|.png\$|.pptx\$|.css\$|.html\$|.ini\$' | wc -l").trim() 47 println DOC_CHANGE 48 CODE_CHANGE = sh(returnStdout: true, script: "git diff-tree --no-commit-id --name-only -r HEAD | egrep -v '.md\$|.rst\$|.txt\$|conf.py\$|.png\$|.pptx\$|.css\$|.html\$|.ini\$' | wc -l").trim() 49 println CODE_CHANGE 50 } 51 // Load properties from ci.properties file 52 props = fabBuildLibrary.loadProperties() 53 // Set PATH 54 env.GOROOT = "/opt/go/go" + props["GO_VER"] + ".linux." + "$MARCH" 55 env.GOPATH = "$WORKSPACE/gopath" 56 env.PATH = "$GOROOT/bin:$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:${nodeHome}/bin:$PATH" 57 } 58 59 if (DOC_CHANGE > '0' && CODE_CHANGE == '0') { 60 sh "echo -e \033[1m ONLY DOC BUILD\033[0m" 61 docsBuild() 62 } else if (DOC_CHANGE > '0' && CODE_CHANGE > '0') { 63 sh "echo -e \033[1m CODE AND DOC BUILD\033[0m" 64 basicChecks() 65 docsBuild() 66 runTests() 67 } else { 68 sh "echo -e \033[1m CODE BUILD\033[0m" 69 basicChecks() // basic checks 70 sh "echo -e \033[1m CODE TESTS\033[0m" 71 runTests() // e2e on merge and unit, fvt tests on parallel 72 } 73 } finally { // post build actions 74 // Don't fail the build if coverage report is not generated 75 step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, 76 coberturaReportFile: '**/coverage.xml', failUnhealthy: false, failUnstable: false, 77 failNoReports: false, maxNumberOfBuilds: 0, sourceEncoding: 'ASCII', zoomCoverageChart: false]) 78 // Don't fail the build if doc output is missing 79 publishHTML([allowMissing: true, 80 alwaysLinkToLastBuild: true, 81 keepAll: true, 82 reportDir: 'html', 83 reportFiles: 'index.html', 84 reportName: 'Docs Output' 85 ]) 86 // Don't fail the build if there is no log file 87 archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log' 88 // Send notifications only for merge failures 89 if (env.JOB_TYPE == "merge") { 90 if (currentBuild.result == 'FAILURE') { 91 // Send notification to rocketChat channel 92 // Send merge build failure email notifications to the submitter 93 sendNotifications(currentBuild.result, props["CHANNEL_NAME"]) 94 } 95 } 96 // Delete containers 97 fabBuildLibrary.deleteContainers() 98 // Delete unused docker images (none,dev,test-vp etc..) 99 fabBuildLibrary.deleteUnusedImages() 100 // Delete workspace when build is done 101 cleanWs notFailBuild: true 102 } // end finally block 103 } // end build stages 104 105 def docsBuild () { 106 def ROOTDIR = pwd() 107 stage("Docs Build") { 108 try { 109 dir("$ROOTDIR/$BASE_DIR") { 110 sh ''' set +x -ue 111 echo "-------> tox VERSION" 112 tox --version 113 pip freeze 114 tox -edocs 115 cp -r docs/_build/html/ $WORKSPACE 116 ''' 117 } 118 } catch (err) { 119 failure_stage = "Docs Build" 120 currentBuild.result = 'FAILURE' 121 throw err 122 } 123 } 124 } 125 126 def basicChecks() { 127 def ROOTDIR = pwd() 128 stage("Basic Checks") { 129 wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { 130 try { 131 dir("$ROOTDIR/$BASE_DIR") { 132 // runs all check conditions (license, format, imports, lint and vet) 133 sh 'make checks' 134 } 135 } catch (err) { 136 failure_stage = "basicChecks" 137 currentBuild.result = 'FAILURE' 138 throw err 139 } 140 } 141 } 142 } 143 144 def fabCar() { 145 def ROOTDIR = pwd() 146 stage("Fab Car Tests") { 147 withEnv(["BASE_FOLDER=${WORKSPACE}/gopath/src/github.com/hyperledger"]) { 148 wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { 149 try { 150 // Clone fabric-samples repository 151 fabBuildLibrary.cloneScm('fabric-samples', '$GERRIT_BRANCH') 152 sh 'echo npm version \$(npm -v)' 153 sh 'echo node version \$(node -v)' 154 // Delete all containers 155 fabBuildLibrary.deleteContainers() 156 // Delete unused docker images (none,dev,test-vp etc..) 157 fabBuildLibrary.deleteUnusedImages() 158 dir("$ROOTDIR/gopath/src/github.com/hyperledger/fabric-samples/scripts/ci_scripts") { 159 sh './fabcar.sh' 160 } 161 } catch (err) { 162 failure_stage = "fabCar" 163 currentBuild.result = 'FAILURE' 164 throw err 165 } 166 } 167 } 168 } 169 } 170 171 def e2e_sdk_node() { 172 def ROOTDIR = pwd() 173 stage("e2e_sdk_node") { 174 wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { 175 try { 176 // Clone fabric-sdk-node repository 177 fabBuildLibrary.cloneScm('fabric-sdk-node', '$GERRIT_BRANCH') 178 sh 'echo npm version \$(npm -v)' 179 sh 'echo node version \$(node -v)' 180 // Delete all containers 181 fabBuildLibrary.deleteContainers() 182 // Delete unused docker images (none,dev,test-vp etc..) 183 fabBuildLibrary.deleteUnusedImages() 184 dir("$ROOTDIR/gopath/src/github.com/hyperledger/fabric-sdk-node") { 185 sh '''set +x -ue 186 npm install 187 npm install -g gulp 188 echo " ==== generate certificates using cryptogen ==== " 189 gulp install-and-generate-certs 190 echo " ==== Run run-end-to-end ==== " 191 gulp run-end-to-end 192 ''' 193 } 194 } catch (err) { 195 failure_stage = "e2e_sdk_node" 196 currentBuild.result = 'FAILURE' 197 throw err 198 } 199 } 200 } 201 } 202 203 def e2e_sdk_java() { 204 def ROOTDIR = pwd() 205 stage("e2e_sdk_java") { 206 wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { 207 try { 208 // Clone fabric-sdk-java repository 209 fabBuildLibrary.cloneScm('fabric-sdk-java', '$GERRIT_BRANCH') 210 // Delete all containers 211 fabBuildLibrary.deleteContainers() 212 // Delete unused docker images (none,dev,test-vp etc..) 213 fabBuildLibrary.deleteUnusedImages() 214 sh 'docker ps -a && docker images' 215 dir("$ROOTDIR/gopath/src/github.com/hyperledger/fabric-sdk-java") { 216 sh '''set +x -ue 217 export WD=$WORKSPACE/gopath/src/github.com/hyperledger/fabric-sdk-java 218 export GOPATH=$WD/src/test/fixture 219 cd $WD/src/test 220 chmod +x cirun.sh 221 ./cirun.sh 222 ''' 223 } 224 } catch (err) { 225 failure_stage = "e2e_sdk_java" 226 currentBuild.result = 'FAILURE' 227 throw err 228 } 229 } 230 } 231 } 232 233 def runTests() { 234 def ROOTDIR = pwd() 235 stage ("Tests") { 236 parallel ( 237 "e2e-Tests" : { 238 // Run e2e tests only on Merge job 239 if (env.JOB_TYPE == "merge") { 240 stage("e2e-Tests") { 241 wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { 242 try { 243 // Build fabri-ca docker images and binaries 244 fabBuildLibrary.fabBuildImages('fabric-ca', 'dist docker') 245 // Clone fabric repository 246 fabBuildLibrary.cloneScm('fabric', '$GERRIT_BRANCH') 247 // Build fabric images and binaries 248 fabBuildLibrary.fabBuildImages('fabric', 'dist docker') 249 // Pull thirdparty images from DockerHub 250 fabBuildLibrary.pullThirdPartyImages(props["FAB_BASEIMAGE_VERSION"], props["FAB_THIRDPARTY_IMAGES_LIST"]) 251 // Pull latest stable images from nexus3 252 fabBuildLibrary.pullDockerImages(props["FAB_BASE_VERSION"], props["FAB_IMAGES_LIST"]) 253 // Test fabcar on fabric-samples 254 fabCar() 255 // Test e2e tests on sdk-node 256 e2e_sdk_node() 257 // Test e2e tests on sdk-java 258 e2e_sdk_java() 259 260 } catch (err) { 261 failure_stage = "e2e-Tests" 262 currentBuild.result = 'FAILURE' 263 throw err 264 } 265 } 266 } 267 } 268 }, 269 270 "Unit Tests" : { 271 node('hyp-x') { 272 stage("UnitTests") { 273 wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { 274 try { 275 // delete working directory 276 deleteDir() 277 // Clean build environment before start the build 278 fabBuildLibrary.cleanupEnv() 279 // Clone repository 280 fabBuildLibrary.cloneRefSpec('fabric-ca') 281 dir("$ROOTDIR/$BASE_DIR") { 282 // Performs checks first and runs the go-test based unit tests 283 sh 'make unit-test int-tests docs' 284 // Stash the coverage report 285 stash name: "coverageReport", includes: "**/coverage.xml" 286 } 287 } 288 catch (err) { 289 failure_stage = "UnitTests" 290 currentBuild.result = 'FAILURE' 291 throw err 292 } 293 } 294 } 295 } 296 }, 297 "FVT Tests" : { 298 node('hyp-x') { 299 stage("FVT Tests") { 300 wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { 301 try { 302 // delete working directory 303 deleteDir() 304 // Clean build environment before start the build 305 fabBuildLibrary.cleanupEnv() 306 // Clone repository 307 fabBuildLibrary.cloneRefSpec('fabric-ca') 308 dir("$ROOTDIR/$BASE_DIR") { 309 // Run FVT Tests 310 sh 'make fvt-tests' 311 } 312 } catch (err) { 313 failure_stage = "FVT Tests" 314 currentBuild.result = 'FAILURE' 315 throw err 316 } 317 } 318 } 319 } 320 }, 321 failFast: true ) // Stop the build flow if one job fails 322 stage("Unstash") { 323 if (DOC_CHANGE > '0' && CODE_CHANGE == '0') { 324 // unstash not required for doc only builds 325 println "Unstash not required" 326 } else { 327 try { 328 dir("$ROOTDIR") { 329 println "Unstash stashed files" 330 // unstash coverageReport on main job 331 unstash 'coverageReport' 332 } 333 } 334 catch (err) { 335 failure_stage = "unstash" 336 currentBuild.result = 'FAILURE' 337 throw err 338 } 339 } 340 } 341 } // stage parallel 342 } // runTests