FAB-12608 Update pipeline script

Change-Id: Ic6ea51389ea6789952fcd4cb60bb518a08d3b176
Signed-off-by: rameshthoomu <rameshbabu.thoomu@gmail.com>
This commit is contained in:
rameshthoomu 2018-10-25 11:39:21 -04:00
parent 595fed4408
commit 5a121b6b27
3 changed files with 117 additions and 116 deletions

68
Jenkinsfile vendored
View file

@ -6,8 +6,18 @@
// Pipeline script for fabric-samples // Pipeline script for fabric-samples
node ('hyp-x') { // trigger build on x86_64 node node ('hyp-x') { // trigger build on x86_64 node
timestamps {
try {
def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name> def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name>
env.PROJECT_DIR = "gopath/src/github.com/hyperledger" env.PROJECT_DIR = "gopath/src/github.com/hyperledger"
env.ARCH = "amd64"
env.NODE_VER = "8.9.4" // NodeJs version
env.VERSION = sh(returnStdout: true, script: 'curl -O https://raw.githubusercontent.com/hyperledger/fabric/release-1.2/Makefile && cat Makefile | grep "PREV_VERSION =" | cut -d "=" -f2').trim()
env.VERSION = "$VERSION"
env.BASE_IMAGE_VER = sh(returnStdout: true, script: 'cat Makefile | grep BASEIMAGE_RELEASE= | cut -d "=" -f2').trim()
env.BASE_IMAGE_TAG = "${ARCH}-${BASE_IMAGE_VER}"
env.GOPATH = "$WORKSPACE/gopath"
env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:~/npm/bin:/home/jenkins/.nvm/versions/node/v${NODE_VER}/bin:$PATH"
def failure_stage = "none" def failure_stage = "none"
// delete working directory // delete working directory
deleteDir() deleteDir()
@ -24,10 +34,11 @@ node ('hyp-x') { // trigger build on x86_64 node
} }
catch (err) { catch (err) {
failure_stage = "Fetch patchset" failure_stage = "Fetch patchset"
currentBuild.result = 'FAILURE'
throw err throw err
} }
} }
// clean environment and get env data // clean environment and get env data
stage("Clean Environment - Get Env Info") { stage("Clean Environment - Get Env Info") {
try { try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") { dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
@ -36,13 +47,15 @@ node ('hyp-x') { // trigger build on x86_64 node
} }
catch (err) { catch (err) {
failure_stage = "Clean Environment - Get Env Info" failure_stage = "Clean Environment - Get Env Info"
currentBuild.result = 'FAILURE'
throw err throw err
} }
} }
// Pull Fabric Images // Pull Fabric Images
stage("Pull third_party images") { stage("Pull ThirdParty Images") {
// making the output color coded
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try { try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") { dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --pull_Thirdparty_Images' sh './CI_Script.sh --pull_Thirdparty_Images'
@ -50,37 +63,33 @@ node ('hyp-x') { // trigger build on x86_64 node
} }
catch (err) { catch (err) {
failure_stage = "Pull third_party docker images" failure_stage = "Pull third_party docker images"
currentBuild.result = 'FAILURE'
throw err throw err
} }
}
} }
// Pull Fabric Images // Pull Fabric, fabric-ca Images
stage("Pull fabric images") { stage("Pull Docker Images") {
// making the output color coded
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try { try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") { dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --pull_Fabric_Images' sh './CI_Script.sh --pull_Docker_Images'
} }
} }
catch (err) { catch (err) {
failure_stage = "Pull fabric docker images" failure_stage = "Pull fabric, fabric-ca docker images"
currentBuild.result = 'FAILURE'
throw err throw err
} }
}
} }
// Pull Fabric-ca // Run byfn, eyfn tests (default, custom channel, couchdb, nodejs chaincode)
stage("Pull fabric-ca images") {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --pull_Fabric_CA_Image'
}
}
catch (err) {
failure_stage = "Pull fabric-ca docker image"
throw err
}
}
// Run byfn, eyfn tests (default, custom channel, couchdb, nodejs chaincode, fabric-ca samples)
stage("Run byfn_eyfn Tests") { stage("Run byfn_eyfn Tests") {
// making the output color coded
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try { try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") { dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --byfn_eyfn_Tests' sh './CI_Script.sh --byfn_eyfn_Tests'
@ -88,7 +97,22 @@ node ('hyp-x') { // trigger build on x86_64 node
} }
catch (err) { catch (err) {
failure_stage = "byfn_eyfn_Tests" failure_stage = "byfn_eyfn_Tests"
currentBuild.result = 'FAILURE'
throw err throw err
} }
}
} }
} finally {
// Archive the artifacts
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log'
// Sends notification to Rocket.Chat jenkins-robot channel
if (env.GERRIT_EVENT_TYPE == 'change-merged') {
if (currentBuild.result == 'FAILURE') { // Other values: SUCCESS, UNSTABLE
rocketSend channel: 'jenkins-robot', message: "Build Notification - STATUS: ${currentBuild.result} - BRANCH: ${env.GERRIT_BRANCH} - PROJECT: ${env.PROJECT} - (<${env.BUILD_URL}|Open>)"
}
}
}
// End Timestamps block
}
// End Node block
} }

View file

@ -1,34 +1,11 @@
#!/bin/bash -e #!/bin/bash
# #
# Copyright IBM Corp All Rights Reserved # Copyright IBM Corp All Rights Reserved
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
# exit on first error
export BASE_FOLDER=$WORKSPACE/gopath/src/github.com/hyperledger
export PROJECT_VERSION=1.2.1-stable
export NEXUS_URL=nexus3.hyperledger.org:10001
export ORG_NAME="hyperledger/fabric" export ORG_NAME="hyperledger/fabric"
export NODE_VER=8.9.4 # Default nodejs version
# Fetch baseimage version
curl -L https://raw.githubusercontent.com/hyperledger/fabric/master/Makefile > Makefile
export BASE_IMAGE_VER=`cat Makefile | grep BASEIMAGE_RELEASE= | cut -d "=" -f2`
echo "-----------> BASE_IMAGE_VER" $BASE_IMAGE_VER
export OS_VER=$(dpkg --print-architecture)
echo "-----------> OS_VER" $OS_VER
export BASE_IMAGE_TAG=$OS_VER-$BASE_IMAGE_VER
# Fetch Go Version from fabric ci.properties file
curl -L https://raw.githubusercontent.com/hyperledger/fabric/master/ci.properties > ci.properties
export GO_VER=`cat ci.properties | grep GO_VER | cut -d "=" -f 2`
echo "-----------> GO_VER" $GO_VER
# Published stable version from nexus
export STABLE_TAG=$OS_VER-$PROJECT_VERSION
echo "-----------> STABLE_TAG" $STABLE_TAG
Parse_Arguments() { Parse_Arguments() {
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
@ -36,14 +13,8 @@ Parse_Arguments() {
--env_Info) --env_Info)
env_Info env_Info
;; ;;
--SetGopath) --pull_Docker_Images)
setGopath pull_Docker_Images
;;
--pull_Fabric_Images)
pull_Fabric_Images
;;
--pull_Fabric_CA_Image)
pull_Fabric_CA_Image
;; ;;
--clean_Environment) --clean_Environment)
clean_Environment clean_Environment
@ -117,63 +88,49 @@ env_Info() {
docker info docker info
docker-compose version docker-compose version
pgrep -a docker pgrep -a docker
docker images
docker ps -a
} }
setGopath() {
echo "-----------> set GOPATH"
echo
export GOPATH=$WORKSPACE/gopath
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
export PATH=$GOROOT/bin:$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:~/npm/bin:/home/jenkins/.nvm/versions/node/v6.9.5/bin:/home/jenkins/.nvm/versions/node/v$NODE_VER/bin:$PATH
export GOROOT=/opt/go/go$GO_VER.linux.$OS_VER
export PATH=$GOROOT/bin:$PATH
}
# Pull Thirdparty Docker images (Kafka, couchdb, zookeeper) # Pull Thirdparty Docker images (Kafka, couchdb, zookeeper)
pull_Thirdparty_Images() { pull_Thirdparty_Images() {
for IMAGES in kafka couchdb zookeeper; do for IMAGES in kafka couchdb zookeeper; do
echo "-----------> Pull $IMAGE image" echo "-----------> BASE_IMGAGE_TAG:" ${BASE_IMAGE_TAG}
echo "-----------> Pull $IMAGES image"
echo echo
docker pull $ORG_NAME-$IMAGES:$BASE_IMAGE_TAG docker pull $ORG_NAME-$IMAGES:${BASE_IMAGE_TAG} > /dev/null 2>&1
docker tag $ORG_NAME-$IMAGES:$BASE_IMAGE_TAG $ORG_NAME-$IMAGES if [ $? -ne 0 ]; then
echo -e "\033[31m FAILED to pull docker images" "\033[0m"
exit 1
fi
docker tag $ORG_NAME-$IMAGES:${BASE_IMAGE_TAG} $ORG_NAME-$IMAGES
done done
echo echo
docker images | grep hyperledger/fabric docker images | grep hyperledger/fabric
} }
# pull fabric images from nexus # pull fabric, fabric-ca images
pull_Fabric_Images() { pull_Docker_Images() {
setGopath fabric # set gopath echo
for IMAGES in peer orderer tools ccenv; do echo "-----------> VERSION:" $VERSION
for IMAGES in peer orderer tools ccenv ca; do
echo "-----------> pull $IMAGES image" echo "-----------> pull $IMAGES image"
echo echo
docker pull $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG docker pull $ORG_NAME-$IMAGES:$VERSION > /dev/null 2>&1
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES if [ $? -ne 0 ]; then
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES:$STABLE_TAG echo -e "\033[31m FAILED to pull docker images" "\033[0m"
docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG exit 1
fi
docker tag $ORG_NAME-$IMAGES:$VERSION $ORG_NAME-$IMAGES
done done
echo echo
docker images | grep hyperledger/fabric docker images | grep hyperledger/fabric
} }
# pull fabric-ca images from nexus
pull_Fabric_CA_Image() {
echo
setGopath fabric-ca
for IMAGES in ca ca-peer ca-orderer ca-tools; do
echo "-----------> pull $IMAGES image"
echo
docker pull $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES:$STABLE_TAG
docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG
done
echo
docker images | grep hyperledger/fabric-ca
}
# run byfn,eyfn tests # run byfn,eyfn tests
byfn_eyfn_Tests() { byfn_eyfn_Tests() {
echo echo
echo "-----------> Execute Byfn and Eyfn Tests" echo "-----------> Execute Byfn and Eyfn Tests"
./byfn_eyfn.sh ./byfn_eyfn.sh
if [ $? -ne 0 ]; then
echo -e "\033[31m FAILED BYFN Tests" "\033[0m"
fi
} }
Parse_Arguments $@ Parse_Arguments $@

View file

@ -5,25 +5,52 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
ARCH=$(dpkg --print-architecture) # docker container list
echo "-----------> ARCH" $ARCH CONTAINER_LIST=(peer0.org1 peer1.org1 peer0.org2 peer1.org2 peer0.org3 peer1.org3 orderer)
COUCHDB_CONTAINER_LIST=(couchdb0 couchdb1 couchdb2 couchdb3 couchdb4 couchdb5)
# linux-amd64, linux-s390x
MARCH=$(uname -s|tr '[:upper:]' '[:lower:]') MARCH=$(uname -s|tr '[:upper:]' '[:lower:]')
echo "-----------> MARCH" $MARCH echo "-----------> MARCH" $MARCH
VERSION=1.2.1
MVN_METADATA=$(echo "https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric-$VERSION-stable/maven-metadata.xml")
curl -L "$MVN_METADATA" > maven-metadata.xml
RELEASE_TAG=$(cat maven-metadata.xml | grep release)
COMMIT=$(echo $RELEASE_TAG | awk -F - '{ print $4 }' | cut -d "<" -f1)
echo "-----------> BASE_VERSION = $VERSION"
cd $BASE_FOLDER/fabric-samples || exit
curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric-$VERSION-stable/$MARCH-$ARCH.$VERSION-stable-$COMMIT/hyperledger-fabric-$VERSION-stable-$MARCH-$ARCH.$VERSION-stable-$COMMIT.tar.gz | tar xz
cd $WORKSPACE/$PROJECT_DIR/fabric-samples || exit
# Download fabric binaries from nexus
curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/$MARCH-$ARCH-$VERSION/hyperledger-fabric-$MARCH-$ARCH-$VERSION.tar.gz | tar xz
if [ $? -ne 0 ]; then
echo -e "\033[31m FAILED to download binaries" "\033[0m"
exit 1
fi
cd first-network || exit cd first-network || exit
export PATH=gopath/src/github.com/hyperledger/fabric-samples/bin:$PATH export PATH=gopath/src/github.com/hyperledger/fabric-samples/bin:$PATH
err_Check() { logs() {
# Create Docker_Container_Logs directory
mkdir -p $WORKSPACE/Docker_Container_Logs
# Save Container logs in Docker_Container_Logs directory
for CONTAINER in ${CONTAINER_LIST[*]}; do
docker logs $CONTAINER.example.com >& $WORKSPACE/Docker_Container_Logs/$CONTAINER-$1.log
echo
done
}
if [ ! -z $2 ]; then
for CONTAINER in ${COUCHDB_CONTAINER_LIST[*]}; do
docker logs $CONTAINER >& $WORKSPACE/Docker_Container_Logs/$CONTAINER-$1.log
echo
done
fi
copy_logs() {
# Call logs function
logs $2 $3
if [ $1 != 0 ]; then if [ $1 != 0 ]; then
echo "Error: -----------> $2 test case failed" echo -e "\033[31m $2 test case is FAILED" "\033[0m"
exit 1 exit 1
fi fi
} }
@ -32,32 +59,25 @@ fi
echo "#################################################################" echo "#################################################################"
echo y | ./byfn.sh -m down echo y | ./byfn.sh -m down
echo y | ./byfn.sh -m up -t 60 echo y | ./byfn.sh -m up -t 60
err_Check $? default-channel copy_logs $? default-channel
echo y | ./eyfn.sh -m up -t 60 echo y | ./eyfn.sh -m up -t 60
err_Check $? default-channel copy_logs $? default-channel
echo y | ./eyfn.sh -m down echo y | ./eyfn.sh -m down
echo echo
echo "############### BYFN,EYFN CUSTOM CHANNEL WITH COUCHDB TEST ##############" echo "############### BYFN,EYFN CUSTOM CHANNEL WITH COUCHDB TEST ##############"
echo "#########################################################################" echo "#########################################################################"
echo y | ./byfn.sh -m up -c custom-channel-couchdb -s couchdb -t 75 -d 15 echo y | ./byfn.sh -m up -c custom-channel-couchdb -s couchdb -t 75 -d 15
err_Check $? custom-channel-couch couchdb copy_logs $? custom-channel-couch couchdb
echo y | ./eyfn.sh -m up -c custom-channel-couchdb -s couchdb -t 75 -d 15 echo y | ./eyfn.sh -m up -c custom-channel-couchdb -s couchdb -t 75 -d 15
err_Check $? custom-channel-couch copy_logs $? custom-channel-couch
echo y | ./eyfn.sh -m down echo y | ./eyfn.sh -m down
echo echo
echo "############### BYFN,EYFN WITH NODE Chaincode. TEST ################" echo "############### BYFN,EYFN WITH NODE Chaincode. TEST ################"
echo "####################################################################" echo "####################################################################"
echo y | ./byfn.sh -m up -l node -t 60 echo y | ./byfn.sh -m up -l node -t 60
err_Check $? default-channel-node copy_logs $? default-channel-node
echo y | ./eyfn.sh -m up -l node -t 60 echo y | ./eyfn.sh -m up -l node -t 60
err_Check $? default-channel-node copy_logs $? default-channel-node
echo y | ./eyfn.sh -m down echo y | ./eyfn.sh -m down
echo "############### FABRIC-CA SAMPLES TEST ########################"
echo "###############################################################"
cd $WORKSPACE/gopath/src/github.com/hyperledger/fabric-samples/fabric-ca
./start.sh
err_Check $? fabric-ca
./stop.sh