|
| 1 | +#!groovy |
1 | 2 | // Copyright IBM Corp All Rights Reserved
|
2 | 3 | //
|
3 | 4 | // SPDX-License-Identifier: Apache-2.0
|
4 | 5 | //
|
5 | 6 |
|
6 |
| -// Pipeline script for fabric-samples |
| 7 | +// Jenkinfile will get triggered on verify and merge jobs and run byfn, eyfn and fabcar |
| 8 | +// tests. |
7 | 9 |
|
8 |
| -node ('hyp-x') { // trigger build on x86_64 node |
9 |
| - timestamps { |
10 |
| - try { |
11 |
| - def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name> |
12 |
| - def nodeHome = tool 'nodejs-8.11.3' |
13 |
| - env.ARCH = "amd64" |
14 |
| - env.VERSION = sh(returnStdout: true, script: 'curl -O https://raw.githubusercontent.com/hyperledger/fabric/master/Makefile && cat Makefile | grep "BASE_VERSION =" | cut -d "=" -f2').trim() |
15 |
| - env.VERSION = "$VERSION" // BASE_VERSION from fabric Makefile |
16 |
| - env.BASE_IMAGE_VER = sh(returnStdout: true, script: 'cat Makefile | grep "BASEIMAGE_RELEASE =" | cut -d "=" -f2').trim() // BASEIMAGE Version from fabric Makefile |
17 |
| - env.IMAGE_TAG = "${ARCH}-${VERSION}-stable" // fabric latest stable version from nexus |
18 |
| - env.PROJECT_VERSION = "${VERSION}-stable" |
19 |
| - env.BASE_IMAGE_TAG = "${ARCH}-${BASE_IMAGE_VER}" //fabric baseimage version |
20 |
| - env.PROJECT_DIR = "gopath/src/github.com/hyperledger" |
21 |
| - env.GOPATH = "$WORKSPACE/gopath" |
22 |
| - env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:${nodeHome}/bin:$PATH" |
23 |
| - def jobname = sh(returnStdout: true, script: 'echo ${JOB_NAME} | grep -q "verify" && echo patchset || echo merge').trim() |
24 |
| - def failure_stage = "none" |
25 |
| - // delete working directory |
26 |
| - deleteDir() |
27 |
| - stage("Fetch Patchset") { // fetch gerrit refspec on latest commit |
28 |
| - try { |
29 |
| - if (jobname == "patchset") { |
30 |
| - println "$GERRIT_REFSPEC" |
31 |
| - println "$GERRIT_BRANCH" |
32 |
| - checkout([ |
33 |
| - $class: 'GitSCM', |
34 |
| - branches: [[name: '$GERRIT_REFSPEC']], |
35 |
| - extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'gopath/src/github.com/hyperledger/$PROJECT'], [$class: 'CheckoutOption', timeout: 10]], |
36 |
| - userRemoteConfigs: [[credentialsId: 'hyperledger-jobbuilder', name: 'origin', refspec: '$GERRIT_REFSPEC:$GERRIT_REFSPEC', url: '$GIT_BASE']]]) |
37 |
| - } else { |
38 |
| - // Clone fabric-samples on merge |
39 |
| - println "Clone $PROJECT repository" |
40 |
| - checkout([ |
41 |
| - $class: 'GitSCM', |
42 |
| - branches: [[name: 'refs/heads/$GERRIT_BRANCH']], |
43 |
| - extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'gopath/src/github.com/hyperledger/$PROJECT']], |
44 |
| - userRemoteConfigs: [[credentialsId: 'hyperledger-jobbuilder', name: 'origin', refspec: '+refs/heads/$GERRIT_BRANCH:refs/remotes/origin/$GERRIT_BRANCH', url: '$GIT_BASE']]]) |
45 |
| - } |
46 |
| - dir("${ROOTDIR}/$PROJECT_DIR/$PROJECT") { |
47 |
| - sh ''' |
48 |
| - # Print last two commit details |
49 |
| - echo |
50 |
| - git log -n2 --pretty=oneline --abbrev-commit |
51 |
| - echo |
52 |
| - ''' |
53 |
| - } |
54 |
| - } |
55 |
| - catch (err) { |
56 |
| - failure_stage = "Fetch patchset" |
57 |
| - currentBuild.result = 'FAILURE' |
58 |
| - throw err |
59 |
| - } |
60 |
| -} |
61 |
| - // clean environment and get env data |
62 |
| - stage("Clean Environment - Get Env Info") { |
63 |
| - try { |
64 |
| - dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") { |
65 |
| - sh './CI_Script.sh --clean_Environment --env_Info' |
66 |
| - } |
67 |
| - } |
68 |
| - catch (err) { |
69 |
| - failure_stage = "Clean Environment - Get Env Info" |
70 |
| - currentBuild.result = 'FAILURE' |
71 |
| - throw err |
72 |
| - } |
73 |
| - } |
74 |
| - |
75 |
| - // Pull Third_party Images |
76 |
| - stage("Pull third_party Images") { |
77 |
| - // making the output color coded |
78 |
| - wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { |
79 |
| - try { |
80 |
| - dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") { |
81 |
| - sh './CI_Script.sh --pull_Thirdparty_Images' |
82 |
| - } |
83 |
| - } |
84 |
| - catch (err) { |
85 |
| - failure_stage = "Pull third_party docker images" |
86 |
| - currentBuild.result = 'FAILURE' |
87 |
| - throw err |
88 |
| - } |
89 |
| - } |
| 10 | +// global shared library from ci-management repository |
| 11 | +// https://github.com/hyperledger/ci-management/tree/master/vars (Global Shared scripts) |
| 12 | +@Library("fabric-ci-lib") _ |
| 13 | + pipeline { |
| 14 | + agent { |
| 15 | + // Execute tests on x86_64 build nodes |
| 16 | + // Set this value from Jenkins Job Configuration |
| 17 | + label env.NODE_ARCH |
| 18 | + } |
| 19 | + options { |
| 20 | + // Using the Timestamper plugin we can add timestamps to the console log |
| 21 | + timestamps() |
| 22 | + // Set build timeout for 60 mins |
| 23 | + timeout(time: 60, unit: 'MINUTES') |
90 | 24 | }
|
91 |
| - |
92 |
| - // Pull Fabric, fabric-ca Images |
93 |
| - stage("Pull Docker Images") { |
94 |
| - // making the output color coded |
95 |
| - wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { |
96 |
| - try { |
97 |
| - dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") { |
98 |
| - sh './CI_Script.sh --pull_Docker_Images' |
99 |
| - } |
100 |
| - } |
101 |
| - catch (err) { |
102 |
| - failure_stage = "Pull fabric, fabric-ca docker images" |
103 |
| - currentBuild.result = 'FAILURE' |
104 |
| - throw err |
105 |
| - } |
106 |
| - } |
| 25 | + environment { |
| 26 | + ROOTDIR = pwd() |
| 27 | + // Applicable only on x86_64 nodes |
| 28 | + // LF team has to install the newer version in Jenkins global config |
| 29 | + // Send an email to helpdesk@hyperledger.org to add newer version |
| 30 | + nodeHome = tool 'nodejs-8.11.3' |
| 31 | + MARCH = sh(returnStdout: true, script: "uname -m | sed 's/x86_64/amd64/g'").trim() |
| 32 | + OS_NAME = sh(returnStdout: true, script: "uname -s|tr '[:upper:]' '[:lower:]'").trim() |
| 33 | + props = "null" |
107 | 34 | }
|
108 |
| - |
109 |
| - // Run byfn, eyfn tests (default, custom channel, couchdb, nodejs chaincode) |
110 |
| - stage("Run byfn_eyfn Tests") { |
111 |
| - // making the output color coded |
112 |
| - wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { |
113 |
| - try { |
114 |
| - dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") { |
115 |
| - sh './CI_Script.sh --byfn_eyfn_Tests' |
116 |
| - } |
117 |
| - } |
118 |
| - catch (err) { |
119 |
| - failure_stage = "byfn_eyfn_Tests" |
120 |
| - currentBuild.result = 'FAILURE' |
121 |
| - throw err |
122 |
| - } |
123 |
| - } |
124 |
| - } |
125 |
| - |
126 |
| - // Run fabcar tests |
127 |
| - stage("Run FabCar Tests") { |
128 |
| - // making the output color coded |
129 |
| - wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { |
130 |
| - try { |
131 |
| - dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") { |
132 |
| - sh './CI_Script.sh --fabcar_Tests' |
133 |
| - } |
134 |
| - } |
135 |
| - catch (err) { |
136 |
| - failure_stage = "fabcar_Tests" |
137 |
| - currentBuild.result = 'FAILURE' |
138 |
| - throw err |
139 |
| - } |
140 |
| - } |
141 |
| - } |
142 |
| - } finally { |
143 |
| - // Archive the artifacts |
144 |
| - archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log' |
145 |
| - // Sends notification to Rocket.Chat jenkins-robot channel |
146 |
| - if (env.JOB_NAME == "fabric-samples-merge-job") { |
147 |
| - if (currentBuild.result == 'FAILURE') { // Other values: SUCCESS, UNSTABLE |
148 |
| - rocketSend message: "Build Notification - STATUS: *${currentBuild.result}* - BRANCH: *${env.GERRIT_BRANCH}* - PROJECT: *${env.PROJECT}* - (<${env.BUILD_URL}|Open>)" |
| 35 | + stages { |
| 36 | + stage('Clean Environment') { |
| 37 | + steps { |
| 38 | + script { |
| 39 | + // delete working directory |
| 40 | + deleteDir() |
| 41 | + // Clean build env before start the build |
| 42 | + fabBuildLibrary.cleanupEnv() |
| 43 | + // Display jenkins environment details |
| 44 | + fabBuildLibrary.envOutput() |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + stage('Checkout SCM') { |
| 49 | + steps { |
| 50 | + script { |
| 51 | + // Get changes from gerrit |
| 52 | + fabBuildLibrary.cloneRefSpec('fabric-samples') |
| 53 | + // Load properties from ci.properties file |
| 54 | + props = fabBuildLibrary.loadProperties() |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + // Pull build artifacts |
| 59 | + stage('Pull Build Artifacts') { |
| 60 | + steps { |
| 61 | + script { |
| 62 | + if(props["IMAGE_SOURCE"] == "build") { |
| 63 | + println "BUILD ARTIFACTS" |
| 64 | + // Set PATH |
| 65 | + env.GOPATH = "$WORKSPACE/gopath" |
| 66 | + env.GOROOT = "/opt/go/go" + props["GO_VER"] + ".linux." + "$MARCH" |
| 67 | + env.PATH = "$GOPATH/bin:$GOROOT/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:${nodeHome}/bin:$PATH" |
| 68 | + // Clone fabric repo |
| 69 | + fabBuildLibrary.cloneScm('fabric', '$GERRIT_BRANCH') |
| 70 | + // Build fabric docker images and binaries |
| 71 | + fabBuildLibrary.fabBuildImages('fabric', 'docker dist') |
| 72 | + // Clone fabric-ca repo |
| 73 | + fabBuildLibrary.cloneScm('fabric-ca', '$GERRIT_BRANCH') |
| 74 | + // Build fabric docker images and binaries |
| 75 | + fabBuildLibrary.fabBuildImages('fabric-ca', 'docker dist') |
| 76 | + // Copy binaries to fabric-samples dir |
| 77 | + sh 'cp -r $ROOTDIR/gopath/src/github.com/hyperledger/fabric/release/$OS_NAME-$MARCH/bin $ROOTDIR/$BASE_DIR/' |
| 78 | + // Pull Thirdparty Docker Images from hyperledger DockerHub |
| 79 | + fabBuildLibrary.pullThirdPartyImages(props["FAB_BASEIMAGE_VERSION"], props["FAB_THIRDPARTY_IMAGES_LIST"]) |
| 80 | + } else { |
| 81 | + dir("$ROOTDIR/$BASE_DIR") { |
| 82 | + // Set PATH |
| 83 | + env.GOPATH = "$WORKSPACE/gopath" |
| 84 | + env.GOROOT = "/opt/go/go" + props["GO_VER"] + ".linux." + "$MARCH" |
| 85 | + env.PATH = "$GOPATH/bin:$GOROOT/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:${nodeHome}/bin:$PATH" |
| 86 | + // Pull Binaries with latest version from nexus2 |
| 87 | + fabBuildLibrary.pullBinaries(props["FAB_BINARY_VER"], props["FAB_BINARY_REPO"]) |
| 88 | + // Pull Docker Images from nexus3 |
| 89 | + fabBuildLibrary.pullDockerImages(props["FAB_BASE_VERSION"], props["FAB_IMAGES_LIST"]) |
| 90 | + // Pull Thirdparty Docker Images from hyperledger DockerHub |
| 91 | + fabBuildLibrary.pullThirdPartyImages(props["FAB_BASEIMAGE_VERSION"], props["FAB_THIRDPARTY_IMAGES_LIST"]) |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + // Run byfn, eyfn tests (default, custom channel, couchdb, nodejs, java chaincode) |
| 98 | + stage('Run byfn_eyfn Tests') { |
| 99 | + steps { |
| 100 | + script { |
| 101 | + // making the output color coded |
| 102 | + wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { |
| 103 | + try { |
| 104 | + dir("$ROOTDIR/$BASE_DIR/scripts/ci_scripts") { |
| 105 | + // Run BYFN, EYFN tests |
| 106 | + sh './ciScript.sh --byfn_eyfn_Tests' |
| 107 | + } |
| 108 | + } |
| 109 | + catch (err) { |
| 110 | + failure_stage = "byfn_eyfn_Tests" |
| 111 | + currentBuild.result = 'FAILURE' |
| 112 | + throw err |
| 113 | + } |
149 | 114 | }
|
150 |
| - } |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + // Run fabcar tests |
| 119 | + stage('Run Fab Car Tests') { |
| 120 | + steps { |
| 121 | + script { |
| 122 | + // making the output color coded |
| 123 | + wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { |
| 124 | + try { |
| 125 | + dir("$ROOTDIR/$BASE_DIR/scripts/ci_scripts") { |
| 126 | + // Run fabcar tests |
| 127 | + sh './ciScript.sh --fabcar_Tests' |
| 128 | + } |
| 129 | + } |
| 130 | + catch (err) { |
| 131 | + failure_stage = "fabcar_Tests" |
| 132 | + currentBuild.result = 'FAILURE' |
| 133 | + throw err |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + } // stages |
| 140 | + post { |
| 141 | + always { |
| 142 | + // Archiving the .log files and ignore if empty |
| 143 | + archiveArtifacts artifacts: '**/*.log', allowEmptyArchive: true |
| 144 | + } |
| 145 | + failure { |
| 146 | + script { |
| 147 | + if (env.JOB_TYPE == 'merge') { |
| 148 | + // Send rocketChat notification to channel |
| 149 | + // Send merge build failure email notifications to the submitter |
| 150 | + sendNotifications(currentBuild.result, props["CHANNEL_NAME"]) |
| 151 | + // Delete workspace when build is done |
| 152 | + cleanWs notFailBuild: true |
| 153 | + } |
| 154 | + } |
151 | 155 | }
|
152 |
| -// End Timestamps block |
153 |
| - } |
154 |
| -// End Node block |
155 |
| -} |
| 156 | + } // post |
| 157 | + } // pipeline |
0 commit comments