Skip to content

Commit

Permalink
FAB-12548 Update CI Pipeline scripts
Browse files Browse the repository at this point in the history
Change-Id: I671e1f78c2131f95b33aaf7a0949f600178c5118
Signed-off-by: rameshthoomu <[email protected]>
  • Loading branch information
rameshthoomu committed Nov 2, 2018
1 parent 0f7c882 commit 49637c6
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 96 deletions.
37 changes: 18 additions & 19 deletions Jenkinsfile.x
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ node ('hyp-x') { // trigger build on x86_64 node
try {
def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name>
env.NODE_VER = "8.11.3"
env.GO_VER = "1.11.1"
env.STABLE_TAG = "1.4.0-stable"
env.VERSION = sh(returnStdout: true, script: 'curl -O https://raw.githubusercontent.com/hyperledger/fabric/master/Makefile && cat Makefile | grep "PREV_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.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:~/npm/bin:/home/jenkins/.nvm/versions/node/v${NODE_VER}/bin:$PATH"
env.GOROOT = "/opt/go${GO_VER}.linux.amd64"
env.PATH = "$GOROOT/bin:$PATH"
def failure_stage = "none"
// delete working directory
deleteDir()
stage("Fetch Patchset") { // fetch gerrit refspec on latest commit
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}"){
sh '''
Expand All @@ -34,10 +36,8 @@ node ('hyp-x') { // trigger build on x86_64 node
throw err
}
}
}
// clean environment and get env data
stage("Clean Environment - Get Env Info") {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-sdk-node/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --clean_Environment --env_Info'
Expand All @@ -48,7 +48,6 @@ node ('hyp-x') { // trigger build on x86_64 node
throw err
}
}
}

// Pull Couchdb Image
stage("Pull Couchdb image") {
Expand Down Expand Up @@ -82,8 +81,8 @@ node ('hyp-x') { // trigger build on x86_64 node
}
}

// Run gulp tests (headless and e2e tests)
stage("Run gulp_Tests") {
// Run gulp tests (headless and integration tests)
stage("Integration Tests") {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-sdk-node/scripts/Jenkins_Scripts") {
Expand All @@ -98,9 +97,9 @@ node ('hyp-x') { // trigger build on x86_64 node
}
}

// Publish unstable npm modules from merged job
// Publish npm modules from merged job
if (env.GERRIT_EVENT_TYPE == "change-merged") {
unstableNpm()
publishNpm()
} else {
echo "------> Don't publish npm modules from verify job"
}
Expand All @@ -114,7 +113,7 @@ if (env.GERRIT_EVENT_TYPE == "change-merged") {

} finally { // Code for coverage report
junit '**/cobertura-coverage.xml'
step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/cobertura-coverage.xml', failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false])
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 (currentBuild.result == 'FAILURE') { // Other values: SUCCESS, UNSTABLE
Expand All @@ -125,18 +124,18 @@ if (env.GERRIT_EVENT_TYPE == "change-merged") {
} // timestamps end here
} // node block end here

def unstableNpm() {
def publishNpm() {
def ROOTDIR = pwd()
// Publish unstable npm modules after successful merge
stage("Publish Unstable npm modules") {
// Publish npm modules after successful merge
stage("Publish npm Modules") {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-sdk-node/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --publish_Unstable'
sh './CI_Script.sh --publish_NpmModules'
}
}
catch (err) {
failure_stage = "publish_Unstable"
failure_stage = "publish_NpmModules"
currentBuild.result = 'FAILURE'
throw err
}
Expand All @@ -150,7 +149,7 @@ def ROOTDIR = pwd()
stage("Publish API Docs") {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-sdk-node/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --publish_Api_Docs'
sh './CI_Script.sh --publish_ApiDocs'
}
}
catch (err) {
Expand Down
22 changes: 11 additions & 11 deletions Jenkinsfile.z
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ node('hyp-z') {

def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name>
env.NODE_VER = "8.11.3"
env.GO_VER = "1.11.1"
env.STABLE_TAG = "1.4.0-stable"
env.VERSION = sh(returnStdout: true, script: 'curl -O https://raw.githubusercontent.com/hyperledger/fabric/master/Makefile && cat Makefile | grep "PREV_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.PROJECT_VERSION = "${VERSION}-stable"
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:~/npm/bin:/home/jenkins/.nvm/versions/node/v${NODE_VER}/bin:$PATH"
env.GOROOT = "/opt/go/go${GO_VER}.linux.s390x"
env.PATH = "$GOROOT/bin:$PATH"
def failure_stage = "none"
// delete working directory
deleteDir()
stage("Fetch Patchset") { // fetch gerrit refspec on latest commit
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}"){
sh '''
Expand All @@ -36,10 +38,8 @@ node('hyp-z') {
throw err
}
}
}
// clean environment and get env data
stage("Clean Environment - Get Env Info") {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-sdk-node/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --clean_Environment --env_Info'
Expand Down Expand Up @@ -67,8 +67,8 @@ node('hyp-z') {
}
}

// Pull fabric, fabric-ca and Javaenv Docker Images
stage("Pull Docker images") {
// Pull fabric, fabric-ca Docker Images
stage("Pull Docker Images") {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-sdk-node/scripts/Jenkins_Scripts") {
Expand All @@ -83,8 +83,8 @@ node('hyp-z') {
}
}

// Run gulp tests (headless and e2e tests)
stage("Run gulp_Tests") {
// Run gulp tests (headless and integration tests)
stage("IntegrationTests") {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-sdk-node/scripts/Jenkins_Scripts") {
Expand Down
47 changes: 18 additions & 29 deletions scripts/Jenkins_Scripts/CI_Script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ export BASE_FOLDER=$WORKSPACE/gopath/src/github.com/hyperledger
export NEXUS_URL=nexus3.hyperledger.org:10001
export ORG_NAME="hyperledger/fabric"

# 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

# Published stable version from nexus
export STABLE_TAG=$OS_VER-$STABLE_TAG
echo "-----------> STABLE_TAG" $STABLE_TAG

# error check
err_Check() {
echo "ERROR !!!! --------> $1 <---------"
Expand All @@ -48,11 +36,11 @@ Parse_Arguments() {
--pull_Thirdparty_Images)
pull_Thirdparty_Images
;;
--publish_Unstable)
publish_Unstable
--publish_NpmModules)
publish_NpmModules
;;
--publish_Api_Docs)
publish_Api_Docs
--publish_ApiDocs)
publish_ApiDocs
;;
esac
shift
Expand Down Expand Up @@ -126,15 +114,16 @@ env_Info() {

# Pull Thirdparty Docker images (couchdb)
pull_Thirdparty_Images() {
echo "--------> BASE_IMAGE_TAG:" ${BASE_IMAGE_TAG}
for IMAGES in couchdb; do
echo "-----------> Pull $IMAGE image"
echo "-----------> Pull $IMAGES image"
echo
docker pull $ORG_NAME-$IMAGES:$BASE_IMAGE_TAG > /dev/null 2>&1
docker pull $ORG_NAME-$IMAGES:${BASE_IMAGE_TAG} > /dev/null 2>&1
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
docker tag $ORG_NAME-$IMAGES:${BASE_IMAGE_TAG} $ORG_NAME-$IMAGES
done
echo
docker images | grep hyperledger/fabric
Expand All @@ -144,14 +133,14 @@ pull_Docker_Images() {
for IMAGES in peer orderer ca; do
echo "-----------> pull $IMAGES image"
echo
docker pull $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG > /dev/null 2>&1
docker pull $NEXUS_URL/$ORG_NAME-$IMAGES:${IMAGE_TAG} > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "\033[31m FAILED to pull docker images" "\033[0m"
exit 1
fi
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
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:${IMAGE_TAG} $ORG_NAME-$IMAGES
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:${IMAGE_TAG} $ORG_NAME-$IMAGES:${ARCH}-${VERSION}
docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:${IMAGE_TAG}
done
echo
docker images | grep hyperledger/fabric
Expand All @@ -160,7 +149,7 @@ pull_Docker_Images() {
# run sdk e2e tests
sdk_E2e_Tests() {
echo
echo "-----------> Execute NODE SDK E2E Tests"
echo "-----------> Execute NODE SDK Integration Tests"
cd ${WORKSPACE}/gopath/src/github.com/hyperledger/fabric-sdk-node || exit
# Install nvm to install multi node versions
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
Expand All @@ -180,7 +169,7 @@ sdk_E2e_Tests() {
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"
rm -rf node_modules && npm install || err_Check "ERROR!!! npm install failed"

echo "------> Run Node SDK Unit, FV, and scenario tests"
echo "============"
Expand All @@ -194,15 +183,15 @@ sdk_E2e_Tests() {
exit 1
fi
}
# Publish unstable npm modules after successful merge on amd64
publish_Unstable() {
# Publish npm modules after successful merge on amd64
publish_NpmModules() {
echo
echo "-----------> Publish unstable npm modules from amd64"
echo "-----------> Publish npm modules from amd64"
./Publish_NPM_Modules.sh
}

# Publish NODE_SDK API docs after successful merge on amd64
publish_Api_Docs() {
publish_ApiDocs() {
echo
echo "-----------> Publish NODE_SDK API docs after successful merge on amd64"
./Publish_API_Docs.sh
Expand Down
71 changes: 34 additions & 37 deletions scripts/Jenkins_Scripts/Publish_NPM_Modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

npmPublish() {

if [[ "$CURRENT_TAG" = *"unstable"* ]] || [[ "$CURRENT_TAG" = *"skip"* ]]; then
if [[ "$CURRENT_TAG" = *"skip"* ]]; then
echo "----> Don't publish npm modules on skip tag"
elif [[ "$CURRENT_TAG" = *"unstable"* ]]; then
echo
UNSTABLE_VER=$(npm dist-tags ls "$1" | awk "/$CURRENT_TAG"":"/'{
ver=$NF
Expand Down Expand Up @@ -37,9 +39,11 @@ npmPublish() {
sed -i 's/\(.*\"version\"\: \"\)\(.*\)/\1'$UNSTABLE_INCREMENT_VERSION\"\,'/' package.json
npm publish --tag $CURRENT_TAG

else
echo "----> Publish $RELEASE from fabric-sdk-node-npm-release-x86_64 job"
fi
else
# Publish node modules on latest tag
echo "========> PUBLISH --> $RELEASE_VERSION"
npm publish --tag $CURRENT_TAG
fi
}

##########################
Expand All @@ -58,38 +62,31 @@ versions() {
echo "===> Current Version --> $RELEASE_VERSION"
}

ARCH=$(uname -m)
echo "----------> ARCH" $ARCH

if [[ "$ARCH" = "s390x" ]] || [[ "$ARCH" = "ppc64le" ]]; then
echo "-------> Publish npm modules only from x86_64 (x) platform, not from $ARCH (z or p) <---------"
else
echo "-------> Publish npm node modules from $ARCH <----------"
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

# Publish fabric-ca-client node module
cd fabric-ca-client
versions
npmPublish fabric-ca-client

# Publish fabric-client node module
cd ../fabric-client
versions
npmPublish fabric-client

# Publish fabric-network node module
if [ -d "../fabric-network" ]; then
cd ../fabric-network
versions
npmPublish fabric-network
fi
echo "-------> Publish npm node modules from x build nodes <----------"
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

# Publish fabric-ca-client node module
cd fabric-ca-client
versions
npmPublish fabric-ca-client

# Publish fabric-client node module
cd ../fabric-client
versions
npmPublish fabric-client

# Publish fabric-network node module
if [ -d "../fabric-network" ]; then
cd ../fabric-network
versions
npmPublish fabric-network
fi

# Publish fabric-common node module
if [ -d "../fabric-common" ]; then
cd ../fabric-common
versions
npmPublish fabric-common
fi
# Publish fabric-common node module
if [ -d "../fabric-common" ]; then
cd ../fabric-common
versions
npmPublish fabric-common
fi

0 comments on commit 49637c6

Please sign in to comment.