forked from hyperledger/fabric-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
153 lines (147 loc) · 6.35 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
// Copyright IBM Corp All Rights Reserved
//
// SPDX-License-Identifier: Apache-2.0
//
// Pipeline script for fabric-samples
node ('hyp-x') { // trigger build on x86_64 node
timestamps {
try {
def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name>
def nodeHome = tool 'nodejs-8.11.3' // NodeJs version
env.ARCH = "amd64"
env.VERSION = sh(returnStdout: true, script: 'curl -O https://raw.githubusercontent.com/hyperledger/fabric/release-1.4/Makefile && cat Makefile | grep "PREV_VERSION =" | cut -d "=" -f2').trim()
env.VERSION = "$VERSION" // PREV_VERSION from fabric Makefile
env.BASE_IMAGE_VER = sh(returnStdout: true, script: 'cat Makefile | grep "BASEIMAGE_RELEASE=" | cut -d "=" -f2').trim() // BASEIMAGE Version from fabric Makefile
env.BASE_IMAGE_TAG = "${ARCH}-${BASE_IMAGE_VER}" //fabric baseimage version
env.PROJECT_DIR = "gopath/src/github.com/hyperledger"
env.GOPATH = "$WORKSPACE/gopath"
env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:${nodeHome}/bin:$PATH"
def jobname = sh(returnStdout: true, script: 'echo ${JOB_NAME} | grep -q "verify" && echo patchset || echo merge').trim()
def failure_stage = "none"
// delete working directory
deleteDir()
stage("Fetch Patchset") { // fetch gerrit refspec on latest commit
try {
if (jobname == "patchset") {
println "$GERRIT_REFSPEC"
println "$GERRIT_BRANCH"
checkout([
$class: 'GitSCM',
branches: [[name: '$GERRIT_REFSPEC']],
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'gopath/src/github.com/hyperledger/$PROJECT'], [$class: 'CheckoutOption', timeout: 10]],
userRemoteConfigs: [[credentialsId: 'hyperledger-jobbuilder', name: 'origin', refspec: '$GERRIT_REFSPEC:$GERRIT_REFSPEC', url: '$GIT_BASE']]])
} else {
// Clone fabric-samples on merge
println "Clone $PROJECT repository"
checkout([
$class: 'GitSCM',
branches: [[name: 'refs/heads/$GERRIT_BRANCH']],
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'gopath/src/github.com/hyperledger/$PROJECT']],
userRemoteConfigs: [[credentialsId: 'hyperledger-jobbuilder', name: 'origin', refspec: '+refs/heads/$GERRIT_BRANCH:refs/remotes/origin/$GERRIT_BRANCH', url: '$GIT_BASE']]])
}
dir("${ROOTDIR}/$PROJECT_DIR/$PROJECT") {
sh '''
# Print last two commit details
echo
git log -n2 --pretty=oneline --abbrev-commit
echo
'''
}
}
catch (err) {
failure_stage = "Fetch patchset"
currentBuild.result = 'FAILURE'
throw err
}
}
// clean environment and get env data
stage("Clean Environment - Get Env Info") {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --clean_Environment --env_Info'
}
}
catch (err) {
failure_stage = "Clean Environment - Get Env Info"
currentBuild.result = 'FAILURE'
throw err
}
}
// Pull Third_party Images
stage("Pull third_party Images") {
// making the output color coded
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --pull_Thirdparty_Images'
}
}
catch (err) {
failure_stage = "Pull third_party docker images"
currentBuild.result = 'FAILURE'
throw err
}
}
}
// Pull Fabric, fabric-ca Images
stage("Pull Docker Images") {
// making the output color coded
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --pull_Docker_Images'
}
}
catch (err) {
failure_stage = "Pull fabric, fabric-ca docker images"
currentBuild.result = 'FAILURE'
throw err
}
}
}
// Run byfn, eyfn tests (default, custom channel, couchdb, nodejs chaincode)
stage("Run byfn_eyfn Tests") {
// making the output color coded
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --byfn_eyfn_Tests'
}
}
catch (err) {
failure_stage = "byfn_eyfn_Tests"
currentBuild.result = 'FAILURE'
throw err
}
}
}
// Run fabcar tests
stage("Run FabCar Tests") {
// making the output color coded
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --fabcar_Tests'
}
}
catch (err) {
failure_stage = "fabcar_Tests"
currentBuild.result = 'FAILURE'
throw err
}
}
}
} finally {
// Archive the artifacts
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log'
// Sends notification to Rocket.Chat jenkins-robot channel
if (env.JOB_NAME == "fabric-samples-merge-job") {
if (currentBuild.result == 'FAILURE') { // Other values: SUCCESS, UNSTABLE
rocketSend message: "Build Notification - STATUS: *${currentBuild.result}* - BRANCH: *${env.GERRIT_BRANCH}* - PROJECT: *${env.PROJECT}* - (<${env.BUILD_URL}|Open>)"
}
}
}
// End Timestamps block
}
// End Node block
}