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: I6bf124ee91f7f15d071c770d52101454dbde3cc5
Signed-off-by: rameshthoomu <rameshbabu.thoomu@gmail.com>
  • Loading branch information
rameshthoomu committed Nov 16, 2018
1 parent a0e7b70 commit 28dbdb3
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 59 deletions.
27 changes: 17 additions & 10 deletions Jenkinsfile.x
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@ timeout(40) {
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.GOPATH = "$WORKSPACE/gopath"
env.NODE_VER = "8.11.3"
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.ARCH = "amd64"
def nodeHome = tool 'nodejs-8.11.3'
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()
stage("Fetch Patchset") { // fetch gerrit refspec on latest commit
try {
dir("${ROOTDIR}"){
dir("${ROOTDIR}") {
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 commit details
git log -n2 --pretty=oneline --abbrev-commit
'''
}
}
Expand All @@ -48,10 +53,12 @@ node ('hyp-x') { // trigger build on x86_64 node
}

// Run gulp tests (headless and Integration tests)
stage("Integration Tests") {
stage("Run 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 All @@ -64,24 +71,24 @@ node ('hyp-x') { // trigger build on x86_64 node
}

// Publish npm modules from merge job
if (env.GERRIT_EVENT_TYPE == "change-merged") {
if (env.JOB_NAME == "fabric-sdk-node-merge-x86_64") {
publishNpm()
} else {
echo "------> Don't publish npm modules from VERIFY job"
}

// Publish API Docs from merged job only
if (env.GERRIT_EVENT_TYPE == "change-merged") {
if (env.JOB_NAME == "fabric-sdk-node-merge-x86_64") {
apiDocs()
} else {
echo "------> Don't publish API Docs from verify job"
echo "------> Don't publish API Docs from VERIFY job"
}
} finally { // Code for coverage report
step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/cobertura-coverage.xml', failUnhealthy: false, failUnstable: false, failNoReports: false, maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false])
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log'
if (env.GERRIT_EVENT_TYPE == "change-merged") {
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>)"
rocketSend message: "Build Notification - STATUS: *${currentBuild.result}* - BRANCH: *${env.GERRIT_BRANCH}* - PROJECT: *${env.PROJECT}* - BUILD_URL - (<${env.BUILD_URL}|Open>)"
}
}
} // finally block end here
Expand Down
19 changes: 13 additions & 6 deletions Jenkinsfile.z
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@ timeout(40) {
node('hyp-z') {
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.GOPATH = "$WORKSPACE/gopath"
env.NODE_VER = "8.11.3"
env.ARCH = "s390x"
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"
// delete working directory
deleteDir()
stage("Fetch Patchset") { // fetch gerrit refspec on latest commit
try {
dir("${ROOTDIR}"){
dir("${ROOTDIR}") {
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
git log -n2 --pretty=oneline --abbrev-commit
'''
}
}
Expand All @@ -48,10 +53,12 @@ node('hyp-z') {
}

// Run gulp tests (headless and IntegrationTests)
stage("Integration Tests") {
stage(" Run 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 All @@ -64,10 +71,10 @@ node('hyp-z') {
}
} finally { // Code for coverage report
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log'
// Sends notification to Rocket.Chat
if (env.GERRIT_EVENT_TYPE == 'change-merged') {
// Send build notifications only on Merge failure to Jenkins-robot RocketChat Channel
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
Expand Down
78 changes: 53 additions & 25 deletions scripts/Jenkins_Scripts/CI_Script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,31 @@
# SPDX-License-Identifier: Apache-2.0
#

export CONTAINER_LIST=(orderer peer0.org1 peer0.org2)

# error check
err_Check() {

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 @@ -43,7 +64,6 @@ function clearContainers () {
echo "---- No containers available for deletion ----"
else
docker rm -f $CONTAINER_IDS || true
docker ps -a
fi
}

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

Expand Down Expand Up @@ -101,45 +120,54 @@ env_Info() {
docker ps -a
}

# run sdk e2e tests
sdk_E2e_Tests() {
echo
echo -e "\033[32m -----------> Execute NODE SDK E2E Tests" "\033[0m"
cd ${WORKSPACE}/gopath/src/github.com/hyperledger/fabric-sdk-node || exit
# Install nvm to install multi node versions
# Install NPM
install_Npm() {

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 -e "\033[32m -----------> Install NodeJS" "\033[0m"
# This also depends on the fabric-baseimage. Make sure you modify there as well.
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/fabric-ca-client && npm install || err_Check "ERROR!!! npm install failed"
npm install -g gulp && npm install -g istanbul
fi
}

# run sdk e2e tests
sdk_E2e_Tests() {

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

echo -e "\033[32m ------> Run Node SDK Unit, FV, and scenario tests" "\033[0m"
# Install NPM before start the tests
install_Npm

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

echo "------> Run node headless & Integration tests"
echo "============"
gulp test || err_Check "ERROR!!! gulp test failed"
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
}

# Publish npm modules after successful merge on amd64
publish_NpmModules() {
echo
Expand Down
4 changes: 2 additions & 2 deletions scripts/Jenkins_Scripts/Publish_API_Docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ gulp doc
SDK_COMMIT=$(git rev-parse --short HEAD)
echo "-------> SDK_COMMIT:" $SDK_COMMIT
TARGET_REPO=$NODE_SDK_USERNAME.github.io.git
git config user.email "fabricsdknode@gmail.com"
git config user.name "fabric-sdk-node"
git config --global user.email "fabricsdknode@gmail.com"
git config --global user.name "fabric-sdk-node"
# Clone SDK_NODE API doc repository
git clone https://github.com/$NODE_SDK_USERNAME/$TARGET_REPO
# Copy API docs to target repository & push to gh-pages URL
Expand Down
28 changes: 12 additions & 16 deletions scripts/Jenkins_Scripts/Publish_NPM_Modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ elif [[ "$CURRENT_TAG" = *"unstable"* ]]; then
sub(/\.[[:digit:]]+$/,"",ver)
print ver}')

echo "===> UNSTABLE VERSION --> $UNSTABLE_VER"
echo "======> UNSTABLE VERSION --> $UNSTABLE_VER"
## Increment unstable version here
UNSTABLE_INCREMENT=$(npm dist-tags ls "$1" | awk "/$CURRENT_TAG"":"/'{
ver=$NF
Expand All @@ -27,46 +27,42 @@ elif [[ "$CURRENT_TAG" = *"unstable"* ]]; then
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
npm publish --tag $CURRENT_TAG

else
# Publish node modules on latest tag
echo -e "\033[32m ========> PUBLISH --> $RELEASE_VERSION" "\033[0m"
echo -e "\033[32m ========> PUBLISH: $RELEASE_VERSION" "\033[0m"
npm publish --tag $CURRENT_TAG
fi
}

##########################
#
# Fetch release version
#
##########################

versions() {

# Get the value of the tag from package.json
CURRENT_TAG=$(cat package.json | grep tag | awk -F\" '{ print $4 }')
echo -e "\033[32m ===> Current TAG --> $CURRENT_TAG" "\033[0m"
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 -e "\033[32m ===> Current Version --> $RELEASE_VERSION" "\033[0m"
RELEASE_VERSION=$(grep '"version":' package.json | cut -d\" -f4)
echo -e "\033[32m ======> Current Version: $RELEASE_VERSION" "\033[0m"

}

echo "-------> Publish npm node modules<----------"
############
# START HERE
############

cd $WORKSPACE/gopath/src/github.com/hyperledger/fabric-sdk-node
# Set NPM_TOKEN from CI configuration
Expand Down

0 comments on commit 28dbdb3

Please sign in to comment.