Skip to content

Commit

Permalink
FABN-1024 Update pipeline scripts
Browse files Browse the repository at this point in the history
This updates the pipeline scripts with credentials to
publish API docs and npm modules. Also, send build notifications
to jenkins-robot rocket chat channel

Change-Id: I7456b0263e9b7f2c491c8565761398cf29160e21
Signed-off-by: rameshthoomu <rameshbabu.thoomu@gmail.com>
  • Loading branch information
rameshthoomu committed Nov 16, 2018
1 parent 177b286 commit 9e3cc71
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 62 deletions.
27 changes: 19 additions & 8 deletions Jenkinsfile.x
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
//
// SPDX-License-Identifier: Apache-2.0
//
timeout(40) {
node ('hyp-x') { // trigger build on x86_64 node
timestamps {
try {
def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name>
env.NODE_VER = "8.11.3"
def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name>)
def nodeHome = tool 'nodejs-8.11.3'
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.ARCH = "amd64"
env.IMAGE_TAG = "${ARCH}-${VERSION}-stable" // fabric latest stable version from nexus
env.PROJECT_VERSION = "${VERSION}-stable"
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:~/npm/bin:/home/jenkins/.nvm/versions/node/v${NODE_VER}/bin:$PATH"
env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:${nodeHome}/bin:$PATH"
def failure_stage = "none"
// delete working directory
deleteDir()
Expand All @@ -24,8 +25,14 @@ node ('hyp-x') { // trigger build on x86_64 node
sh '''
[ -e gopath/src/github.com/hyperledger/fabric-sdk-node ] || mkdir -p $PROJECT_DIR
cd $PROJECT_DIR
# Clone fabric-sdk-node repository
git clone git://cloud.hyperledger.org/mirror/fabric-sdk-node && cd fabric-sdk-node
# Checkout to Branch and Apply patchset on latest commit
git checkout "$GERRIT_BRANCH" && git fetch origin "$GERRIT_REFSPEC" && git checkout FETCH_HEAD
# Print last two commit details
echo "************"
git log -n2 --pretty=oneline --abbrev-commit
echo "************"
'''
}
}
Expand Down Expand Up @@ -66,10 +73,12 @@ node ('hyp-x') { // trigger build on x86_64 node
}

// Run gulp tests (headless and integration tests)
stage("Integration Tests") {
stage("Headless & Integration Tests") {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-sdk-node/scripts/Jenkins_Scripts") {
// Get the testFabricVersion and thirdpartyVersion from package.json
// and Pull the DockerImages from dockerhub and run the Integration Tests
sh './CI_Script.sh --sdk_E2e_Tests'
}
}
Expand Down Expand Up @@ -100,12 +109,14 @@ if (env.JOB_NAME == "fabric-sdk-node-merge-x86_64") {
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log'
if (env.JOB_NAME == "fabric-sdk-node-merge-x86_64") {
if (currentBuild.result == 'FAILURE') { // Other values: SUCCESS, UNSTABLE
rocketSend "Build Notification - STATUS: ${currentBuild.result} - BRANCH: ${env.GERRIT_BRANCH} - PROJECT: ${env.PROJECT} - BUILD_URL: (<${env.BUILD_URL}|Open>)"
// Sends merge failure notifications to Jenkins-robot RocketChat Channel
rocketSend message: "Build Notification - STATUS: *${currentBuild.result}* - BRANCH: *${env.GERRIT_BRANCH}* - PROJECT: *${env.PROJECT}* - BUILD_URL: (<${env.BUILD_URL}|Open>)"
}
}
} // finally block end here
} // timestamps end here
} // node block end here
} // finally block
} // timestamps block
} // node block block
} // timeout block

def publishNpm() {
// Publish npm modules after successful merge
Expand Down
22 changes: 16 additions & 6 deletions Jenkinsfile.z
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
//
// SPDX-License-Identifier: Apache-2.0
//
timeout(40) {
node('hyp-z') {
timestamps {
try {

def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name>
env.NODE_VER = "8.11.3"
// Fetch the BASE_VERSION from fabric master branch to pull images from nexus
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.ARCH = "s390x" // `uname -m`
env.IMAGE_TAG = "${ARCH}-${VERSION}-stable" // fabric latest stable version from nexus
env.IMAGE_TAG = "${ARCH}-${VERSION}-stable" // fabric latest stable version from nexus3
env.PROJECT_VERSION = "${VERSION}-stable"
env.PROJECT_DIR = "gopath/src/github.com/hyperledger"
env.GOPATH = "$WORKSPACE/gopath"
Expand All @@ -25,7 +27,14 @@ node('hyp-z') {
sh '''
[ -e gopath/src/github.com/hyperledger/fabric-sdk-node ] || mkdir -p $PROJECT_DIR
cd $PROJECT_DIR
# Clone sdk-node repository
git clone git://cloud.hyperledger.org/mirror/fabric-sdk-node && cd fabric-sdk-node
# Checkout to Branch and Apply patchset on latest commit
git checkout $GERRIT_BRANCH && git fetch origin "$GERRIT_REFSPEC" && git checkout FETCH_HEAD
# Print last two commit details
echo "***********"
git log -n2 --pretty=oneline --abbrev-commit
echo "***********"
git checkout "$GERRIT_BRANCH" && git fetch origin "$GERRIT_REFSPEC" && git checkout FETCH_HEAD
'''
}
Expand Down Expand Up @@ -69,7 +78,7 @@ node('hyp-z') {
}

// Run gulp tests (headless and integration tests)
stage("IntegrationTests") {
stage("Headless & IntegrationTests") {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-sdk-node/scripts/Jenkins_Scripts") {
Expand All @@ -87,9 +96,10 @@ node('hyp-z') {
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log'
if (env.JOB_NAME == "fabric-sdk-node-merge-s390x") {
if (currentBuild.result == 'FAILURE') { // Other values: SUCCESS, UNSTABLE
rocketSend "Build Notification - STATUS: ${currentBuild.result} - BRANCH: ${env.GERRIT_BRANCH} - PROJECT: ${env.PROJECT} - BUILD_URL: (<${env.BUILD_URL}|Open>)"
rocketSend message: "Build Notification - STATUS: *${currentBuild.result}* - BRANCH: *${env.GERRIT_BRANCH}* - PROJECT: *${env.PROJECT}* - BUILD_URL: (<${env.BUILD_URL}|Open>)"
}
}
} // finally block end here
} // timestamps end here
} // node block end here
} // finally
} // timestamps
} // node
} // timeout
85 changes: 54 additions & 31 deletions scripts/Jenkins_Scripts/CI_Script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,32 @@
# SPDX-License-Identifier: Apache-2.0
#

# exit on first error

export BASE_FOLDER=$WORKSPACE/gopath/src/github.com/hyperledger
# Modify this when change the image tag
export CONTAINER_LIST=(orderer peer0.org1 peer0.org2)
export NEXUS_URL=nexus3.hyperledger.org:10001
export ORG_NAME="hyperledger/fabric"

# error check
err_Check() {
echo "\033[31m $1" "\033[0m"
exit 1

echo -e "\033[31m $1" "\033[0m"
docker images | grep hyperledger && docker ps -a

# Write orderer, peer logs
for CONTAINER in ${CONTAINER_LIST[*]}; do
docker logs $CONTAINER.example.com >& $CONTAINER.log
done

# Write ca logs into ca_peerOrg1.log
docker logs ca_peerOrg1 >& ca_peerOrg1.log
# Write ca logs into ca_peerOrg2.log
docker logs ca_peerOrg2 >& ca_peerOrg2.log
# Write couchdb container logs into couchdb.log file
docker logs couchdb >& couchdb.log

# Copy debug log
cp /tmp/hfc/test-log/*.log $WORKSPACE || true
clean_Environment
exit 1
}

Parse_Arguments() {
Expand Down Expand Up @@ -53,7 +68,6 @@ function clearContainers () {
echo "---- No containers available for deletion ----"
else
docker rm -f $CONTAINER_IDS || true
docker ps -a
fi
}

Expand All @@ -71,7 +85,6 @@ function removeUnwantedImages() {
echo "---- No images available for deletion ----"
else
docker rmi -f $DOCKER_IMAGE_IDS || true
docker images
fi
}

Expand Down Expand Up @@ -107,6 +120,8 @@ env_Info() {
docker info
docker-compose version
pgrep -a docker
docker ps
docker images
}

# pull fabric, fabric-ca images from nexus
Expand Down Expand Up @@ -145,44 +160,52 @@ pull_Docker_Images() {
echo
docker images | grep hyperledger/fabric
}
# Install NPM
install_Npm() {

# run sdk e2e tests
sdk_E2e_Tests() {
echo
echo -e "\033[32m Execute NODE SDK Integration Tests" "\033[0m"
cd ${WORKSPACE}/gopath/src/github.com/hyperledger/fabric-sdk-node || exit
# Install nvm to install multi node versions
echo "-------> ARCH:" $ARCH
if [[ $ARCH == "s390x" || $ARCH == "ppc64le" ]]; then
# Install nvm to install multi node versions
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
# shellcheck source=/dev/null
export NVM_DIR="$HOME/.nvm"
# shellcheck source=/dev/null
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

echo "------> Install NodeJS"
# Install NODE_VER
echo "------> Use $NODE_VER"
nvm install $NODE_VER || true
nvm use --delete-prefix v$NODE_VER --silent
npm install || err_Check "ERROR!!! npm install failed"
npm config set prefix ~/npm && npm install -g gulp && npm install -g istanbul

echo -e "\033[32m npm version ------> $(npm -v)" "\033[0m"
echo -e "\033[32m node version ------> $(node -v)" "\033[0m"

else
echo -e "\033[32m npm version ------> $(npm -v)" "\033[0m"
echo -e "\033[32m node version ------> $(node -v)" "\033[0m"

npm install || err_Check "ERROR!!! npm install failed"
npm config set prefix ~/npm && npm install -g gulp && npm install -g istanbul
~/npm/bin/gulp || err_Check "ERROR!!! gulp failed"
~/npm/bin/gulp ca || err_Check "ERROR!!! gulp ca failed"
rm -rf node_modules && npm install || err_Check "ERROR!!! npm install failed"

echo -e "\033[32m ------> Run Node SDK Unit, FV, and scenario tests" "\033[0m"
echo "============"
~/npm/bin/gulp test
if [ $? == 0 ]; then
# Copy Debug log to $WORKSPACE
cp /tmp/hfc/test-log/*.log $WORKSPACE
else
# Copy Debug log to $WORKSPACE
cp /tmp/hfc/test-log/*.log $WORKSPACE
exit 1
fi
npm install -g gulp && npm install -g istanbul
fi
}

# run sdk e2e tests
sdk_E2e_Tests() {

cd ${WORKSPACE}/gopath/src/github.com/hyperledger/fabric-sdk-node

# Install NPM before start the tests
install_Npm

gulp || err_Check "ERROR!!! gulp failed"
gulp ca || err_Check "ERROR!!! gulp ca failed"

echo -e "\033[32m Execute Headless and Integration Tests" "\033[0m"
gulp test || err_Check "ERROR!!! gulp test failed"
}

# Publish npm modules after successful merge on amd64
publish_NpmModules() {
echo
Expand Down
45 changes: 28 additions & 17 deletions scripts/Jenkins_Scripts/Publish_NPM_Modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,64 @@ npmPublish() {
sub(/.*\./,"",rel)
sub(/\.[[:digit:]]+$/,"",ver)
print ver}')
echo "======> UNSTABLE VERSION:" $UNSTABLE_VER

echo "===> UNSTABLE VERSION --> $UNSTABLE_VER"
UNSTABLE_INCREMENT=$(npm dist-tags ls "$1" | awk "/$CURRENT_TAG"":"/'{
ver=$NF
rel=$NF
sub(/.*\./,"",rel)
sub(/\.[[:digit:]]+$/,"",ver)
print ver"."rel+1}')
echo "===> Incremented UNSTABLE VERSION --> $UNSTABLE_INCREMENT"
echo "======> Incremented UNSTABLE VERSION:" $UNSTABLE_INCREMENT

# Get last digit of the unstable version of $CURRENT_TAG
UNSTABLE_INCREMENT=$(echo $UNSTABLE_INCREMENT| rev | cut -d '.' -f 1 | rev)
echo "--------> UNSTABLE_INCREMENT : $UNSTABLE_INCREMENT"
echo "======> UNSTABLE_INCREMENT:" $UNSTABLE_INCREMENT

# Append last digit with the package.json version
export UNSTABLE_INCREMENT_VERSION=$RELEASE_VERSION.$UNSTABLE_INCREMENT
echo "--------> UNSTABLE_INCREMENT_VERSION" $UNSTABLE_INCREMENT_VERSION
echo "======> UNSTABLE_INCREMENT_VERSION:" $UNSTABLE_INCREMENT_VERSION


# Replace existing version with $UNSTABLE_INCREMENT_VERSION
sed -i 's/\(.*\"version\"\: \"\)\(.*\)/\1'$UNSTABLE_INCREMENT_VERSION\"\,'/' package.json
# Show Version after modify the package.json with latest version to publish
grep '"version":' package.json | cut -d\" -f4
# Publish unstable versions to npm registry
npm publish --tag $CURRENT_TAG
if [ $? != 0 ]; then
echo -e "\033[31m FAILED to Publish $CURRENT_TAG of $1 npm module" "\033[0m"
exit 1
fi
echo -e "\033[32m ========> PUBLISHED $CURRENT_TAG of $1 npm module SUCCESSFULLY" "\033[0m"

else
# Publish node modules on latest tag
echo "========> PUBLISH --> $RELEASE_VERSION"
echo -e "\033[32m ========> PUBLISH $RELEASE_VERSION" "\033[0m"
npm publish --tag $CURRENT_TAG
if [ $? != 0 ]; then
echo -e "\033[31m FAILED TO PUBLISH $CURRENT_TAG of $1 npm module" "\033[0m"
exit 1
fi
echo -e "\033[32m ========> PUBLISHED $CURRENT_TAG of $1 npm module SUCCESSFULLY" "\033[0m"
fi
}

##########################
#
# Fetch release version
#
##########################
versions() {

# Get the unstable tag from package.json
CURRENT_TAG=$(cat package.json | grep tag | awk -F\" '{ print $4 }')
echo "===> Current TAG --> $CURRENT_TAG"
# Get the unstable tag from package.json
CURRENT_TAG=$(grep '"tag":' package.json | cut -d\" -f4)
echo -e "\033[32m ======> Current TAG: $CURRENT_TAG" "\033[0m
# Get the version from package.json
RELEASE_VERSION=$(cat package.json | grep version | awk -F\" '{ print $4 }')
echo "===> Current Version --> $RELEASE_VERSION"
RELEASE_VERSION=$(grep '"version":' package.json | cut -d\" -f4)
echo -e "\033[32m ======> Current Version: $RELEASE_VERSION" "\033[0m"
}
echo "-------> Publish npm node modules from x build nodes <----------"
############
# START HERE
############
echo "----------> START PUBLISHING FROM HERE"
cd $WORKSPACE/gopath/src/github.com/hyperledger/fabric-sdk-node
# Set NPM_TOKEN from CI configuration
npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
Expand Down

0 comments on commit 9e3cc71

Please sign in to comment.