mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 07:25:10 +00:00
This change is to update Jenkinsfile to fetch the patchset for verify jobs and clone the latest commit for merge jobs. Change-Id: I20f9a322eb9f60b648b4b630df2d4565223be916 Signed-off-by: Sambhav Nidamarty <sambhavdutt@gmail.com>
155 lines
6.5 KiB
Groovy
155 lines
6.5 KiB
Groovy
// 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'
|
|
env.ARCH = "amd64"
|
|
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()
|
|
env.VERSION = "$VERSION" // BASE_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.IMAGE_TAG = "${ARCH}-${VERSION}-stable" // fabric latest stable version from nexus
|
|
env.PROJECT_VERSION = "${VERSION}-stable"
|
|
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
|
|
}
|