forked from hyperledger/fabric-samples
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Jenkinsfile
157 lines (155 loc) · 6.25 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!groovy
// Copyright IBM Corp All Rights Reserved
//
// SPDX-License-Identifier: Apache-2.0
//
// Jenkinfile will get triggered on verify and merge jobs and run byfn, eyfn and fabcar
// tests.
// global shared library from ci-management repository
// https://github.com/hyperledger/ci-management/tree/master/vars (Global Shared scripts)
@Library("fabric-ci-lib") _
pipeline {
agent {
// Execute tests on x86_64 build nodes
// Set this value from Jenkins Job Configuration
label env.NODE_ARCH
}
options {
// Using the Timestamper plugin we can add timestamps to the console log
timestamps()
// Set build timeout for 60 mins
timeout(time: 60, unit: 'MINUTES')
}
environment {
ROOTDIR = pwd()
// Applicable only on x86_64 nodes
// LF team has to install the newer version in Jenkins global config
// Send an email to [email protected] to add newer version
nodeHome = tool 'nodejs-8.11.3'
MARCH = sh(returnStdout: true, script: "uname -m | sed 's/x86_64/amd64/g'").trim()
OS_NAME = sh(returnStdout: true, script: "uname -s|tr '[:upper:]' '[:lower:]'").trim()
props = "null"
}
stages {
stage('Clean Environment') {
steps {
script {
// delete working directory
deleteDir()
// Clean build env before start the build
fabBuildLibrary.cleanupEnv()
// Display jenkins environment details
fabBuildLibrary.envOutput()
}
}
}
stage('Checkout SCM') {
steps {
script {
// Get changes from gerrit
fabBuildLibrary.cloneRefSpec('fabric-samples')
// Load properties from ci.properties file
props = fabBuildLibrary.loadProperties()
}
}
}
// Pull build artifacts
stage('Pull Build Artifacts') {
steps {
script {
if(props["IMAGE_SOURCE"] == "build") {
println "BUILD ARTIFACTS"
// Set PATH
env.GOPATH = "$WORKSPACE/gopath"
env.GOROOT = "/opt/go/go" + props["GO_VER"] + ".linux." + "$MARCH"
env.PATH = "$GOPATH/bin:$GOROOT/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:${nodeHome}/bin:$PATH"
// Clone fabric repo
fabBuildLibrary.cloneScm('fabric', '$GERRIT_BRANCH')
// Build fabric docker images and binaries
fabBuildLibrary.fabBuildImages('fabric', 'docker dist')
// Clone fabric-ca repo
fabBuildLibrary.cloneScm('fabric-ca', '$GERRIT_BRANCH')
// Build fabric docker images and binaries
fabBuildLibrary.fabBuildImages('fabric-ca', 'docker dist')
// Copy binaries to fabric-samples dir
sh 'cp -r $ROOTDIR/gopath/src/github.com/hyperledger/fabric/release/$OS_NAME-$MARCH/bin $ROOTDIR/$BASE_DIR/'
// Pull Thirdparty Docker Images from hyperledger DockerHub
fabBuildLibrary.pullThirdPartyImages(props["FAB_BASEIMAGE_VERSION"], props["FAB_THIRDPARTY_IMAGES_LIST"])
} else {
dir("$ROOTDIR/$BASE_DIR") {
// Set PATH
env.GOPATH = "$WORKSPACE/gopath"
env.GOROOT = "/opt/go/go" + props["GO_VER"] + ".linux." + "$MARCH"
env.PATH = "$GOPATH/bin:$GOROOT/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:${nodeHome}/bin:$PATH"
// Pull Binaries with latest version from nexus2
fabBuildLibrary.pullBinaries(props["FAB_BINARY_VER"], props["FAB_BINARY_REPO"])
// Pull Docker Images from nexus3
fabBuildLibrary.pullDockerImages(props["FAB_BASE_VERSION"], props["FAB_IMAGES_LIST"])
// Pull Thirdparty Docker Images from hyperledger DockerHub
fabBuildLibrary.pullThirdPartyImages(props["FAB_BASEIMAGE_VERSION"], props["FAB_THIRDPARTY_IMAGES_LIST"])
}
}
}
}
}
// Run byfn, eyfn tests (default, custom channel, couchdb, nodejs, java chaincode)
stage('Run byfn_eyfn Tests') {
steps {
script {
// making the output color coded
// wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("$ROOTDIR/$BASE_DIR/scripts/ci_scripts") {
// Run BYFN, EYFN tests
sh './ciScript.sh --byfn_eyfn_Tests'
}
}
catch (err) {
failure_stage = "byfn_eyfn_Tests"
currentBuild.result = 'FAILURE'
throw err
}
// }
}
}
}
// Run fabcar tests
stage('Run Fab Car Tests') {
steps {
script {
// making the output color coded
// wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("$ROOTDIR/$BASE_DIR/scripts/ci_scripts") {
// Run fabcar tests
sh './ciScript.sh --fabcar_Tests'
}
}
catch (err) {
failure_stage = "fabcar_Tests"
currentBuild.result = 'FAILURE'
throw err
}
// }
}
}
}
} // stages
post {
always {
// Archiving the .log files and ignore if empty
archiveArtifacts artifacts: '**/*.log', allowEmptyArchive: true
}
failure {
script {
if (env.JOB_TYPE == 'merge') {
// Send rocketChat notification to channel
// Send merge build failure email notifications to the submitter
sendNotifications(currentBuild.result, props["CHANNEL_NAME"])
// Delete workspace when build is done
cleanWs notFailBuild: true
}
}
}
} // post
} // pipeline