Skip to content

Commit 1bd1c2f

Browse files
rameshthoomusykesm
authored andcommitted
FABCI-284 Update CI Pipeline script
This patch updates CI pipeline scripts which utilizes global shared library reusable functions. It also creates ci.properties file with all the parameters required to test the fabric-samples patch. Change-Id: I9ed97c8dd0c07a3677042dbda034043e8a19a0f1 Signed-off-by: rameshthoomu <rameshbabu.thoomu@gmail.com>
1 parent c24abf9 commit 1bd1c2f

File tree

11 files changed

+420
-146
lines changed

11 files changed

+420
-146
lines changed

Jenkinsfile

Lines changed: 147 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,157 @@
1+
#!groovy
12
// Copyright IBM Corp All Rights Reserved
23
//
34
// SPDX-License-Identifier: Apache-2.0
45
//
56

6-
// Pipeline script for fabric-samples
7+
// Jenkinfile will get triggered on verify and merge jobs and run byfn, eyfn and fabcar
8+
// tests.
79

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')
9024
}
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"
10734
}
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+
}
149114
}
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+
}
151155
}
152-
// End Timestamps block
153-
}
154-
// End Node block
155-
}
156+
} // post
157+
} // pipeline

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ are 1.4.0, 1.4.0 and 0.4.14 respectively.
1919
./scripts/bootstrap.sh [version] [ca version] [thirdparty_version]
2020
```
2121

22+
### Continuous Integration
23+
24+
Please have a look at [Continuous Integration Process](docs/fabric-samples-ci.md)
25+
2226
## License <a name="license"></a>
2327

2428
Hyperledger Project source code files are made available under the Apache

basic-network/start.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export MSYS_NO_PATHCONV=1
1313
docker-compose -f docker-compose.yml down
1414

1515
docker-compose -f docker-compose.yml up -d ca.example.com orderer.example.com peer0.org1.example.com couchdb
16+
docker ps -a
1617

1718
# wait for Hyperledger Fabric to start
1819
# incase of errors when running later commands, issue export FABRIC_START_TIMEOUT=<larger number>

ci.properties

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Set "nexus" if you would like to pull images from nexus3
2+
# Set "build" if you would like build fabric, fabric-ca on latest commits
3+
IMAGE_SORUCE=nexus
4+
# set only "javaenv" image if you set IMAGE_SOURCE to "build"
5+
# Pull below list of images from nexus3 if IMAGE_SOURCE is set to "nexus" or "build"
6+
FAB_IMAGES_LIST=ca peer orderer ccenv tools baseos nodeenv javaenv
7+
# Set fabric if you would like pull only fabric binaries
8+
FAB_BINARY_REPO=fabric fabric-ca
9+
# Pull below list of images from Hyperledger DockerHub
10+
FAB_THIRDPARTY_IMAGES_LIST=kafka zookeeper couchdb
11+
# Pull latest binaries of latest commit of release-1.4 from nexus snapshots
12+
# Applicable only when set IMAGE_SOURCE to "nexus"
13+
FAB_BINARY_VER=latest
14+
# Set base version from fabric branch
15+
FAB_BASE_VERSION=2.0.0
16+
# Set base image version from fabric branch
17+
FAB_BASEIMAGE_VERSION=0.4.15
18+
# Set related rocketChat channel name. Default: jenkins-robot
19+
CHANNEL_NAME=jenkins-robot
20+
# Set compaitable go version
21+
GO_VER=1.11.5

0 commit comments

Comments
 (0)