From c47f4ba85c1283bdd4eca1117bd8c9a26c4f44d8 Mon Sep 17 00:00:00 2001 From: Sambhav Nidamarty Date: Mon, 24 Dec 2018 17:41:58 -0500 Subject: [PATCH] FAB-13433 - Update Jenkinsfile configuration This change is to update Jenkinsfile to fetch the patchset for verify jobs and clone the latest commit for merge jobs. Change-Id: I3808a0307a42cb4a2332673918d024bcbea60c9e Signed-off-by: Sambhav Nidamarty --- Jenkinsfile | 57 ++++++++++++++++++---------- scripts/Jenkins_Scripts/CI_Script.sh | 20 +++------- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b7b07494..d4c4112e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,26 +9,44 @@ node ('hyp-x') { // trigger build on x86_64 node timestamps { try { def ROOTDIR = pwd() // workspace dir (/w/workspace/ - env.NODE_VER = "8.11.3" // NodeJs version + def nodeHome = tool 'nodejs-8.11.3' // NodeJs version env.OS_VER = "amd64" env.VERSION = sh(returnStdout: true, script: 'curl -O https://raw.githubusercontent.com/hyperledger/fabric/release-1.3/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 = "${OS_VER}-${BASE_IMAGE_VER}" + env.VERSION = "$VERSION" // PREV_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.BASE_IMAGE_TAG = "${OS_VER}-${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.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 { - dir("${ROOTDIR}") { + if (jobname == "patchset") { + println "$GERRIT_REFSPEC" + println "$GERRIT_BRANCH" + checkout([ + $class: 'GitSCM', + branches: [[name: '$GERRIT_REFSPEC']], + extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: '$BASE_DIR'], [$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: '$BASE_DIR']], + 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 ''' - [ -e gopath/src/github.com/hyperledger/fabric-samples ] || mkdir -p $PROJECT_DIR - cd $PROJECT_DIR - git clone git://cloud.hyperledger.org/mirror/fabric-samples && cd fabric-samples - git fetch origin "$GERRIT_REFSPEC" && git checkout FETCH_HEAD + # Print last two commit details + echo + git log -n2 --pretty=oneline --abbrev-commit + echo ''' } } @@ -37,9 +55,9 @@ node ('hyp-x') { // trigger build on x86_64 node currentBuild.result = 'FAILURE' throw err } - } +} // clean environment and get env data - stage("Cleanup Env") { + stage("Clean Environment - Get Env Info") { try { dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") { sh './CI_Script.sh --clean_Environment --env_Info' @@ -52,7 +70,7 @@ node ('hyp-x') { // trigger build on x86_64 node } } - // Pull Third Party Images (couchdb, zookeeper, kafka) + // Pull Third Party Images (couchdb, zookeeper, kafka) stage("Pull ThirdParty Images") { // making the output color coded wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { @@ -69,8 +87,8 @@ node ('hyp-x') { // trigger build on x86_64 node } } - // Pull Docker Images - stage("Pull Docker images") { + // Pull Fabric, fabric-ca Images + stage("Pull Docker Images") { // making the output color coded wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { try { @@ -79,7 +97,7 @@ node ('hyp-x') { // trigger build on x86_64 node } } catch (err) { - failure_stage = "Pull fabric and fabric-ca docker images" + failure_stage = "Pull fabric, fabric-ca docker images" currentBuild.result = 'FAILURE' throw err } @@ -102,17 +120,18 @@ node ('hyp-x') { // trigger build on x86_64 node } } } + } 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 (env.JOB_NAME == "fabric-samples-merge-job") { 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>)" + rocketSend message: "Build Notification - STATUS: *${currentBuild.result}* - BRANCH: *${env.GERRIT_BRANCH}* - PROJECT: *${env.PROJECT}* - (<${env.BUILD_URL}|Open>)" } } } -// End Try block +// End Timestamps block } // End Node block } diff --git a/scripts/Jenkins_Scripts/CI_Script.sh b/scripts/Jenkins_Scripts/CI_Script.sh index ebbd5c61..0bd5e9ac 100755 --- a/scripts/Jenkins_Scripts/CI_Script.sh +++ b/scripts/Jenkins_Scripts/CI_Script.sh @@ -43,21 +43,13 @@ function clearContainers () { } function removeUnwantedImages() { - DOCKER_IMAGES_SNAPSHOTS=$(docker images | grep snapshot | grep -v grep | awk '{print $1":" $2}') + for i in $(docker images | grep none | awk '{print $3}'); do + docker rmi ${i} || true + done - if [ -z "$DOCKER_IMAGES_SNAPSHOTS" ] || [ "$DOCKER_IMAGES_SNAPSHOTS" = " " ]; then - echo "---- No snapshot images available for deletion ----" - else - docker rmi -f $DOCKER_IMAGES_SNAPSHOTS || true - fi - DOCKER_IMAGE_IDS=$(docker images | grep -v 'base*\|couchdb\|kafka\|zookeeper\|cello' | awk '{print $3}') - - if [ -z "$DOCKER_IMAGE_IDS" ] || [ "$DOCKER_IMAGE_IDS" = " " ]; then - echo "---- No images available for deletion ----" - else - docker rmi -f $DOCKER_IMAGE_IDS || true - docker images - fi + for i in $(docker images | grep -vE ".*baseimage.*(0.4.13|0.4.14)" | grep -vE ".*baseos.*(0.4.13|0.4.14)" | grep -vE ".*couchdb.*(0.4.13|0.4.14)" | grep -vE ".*zoo.*(0.4.13|0.4.14)" | grep -vE ".*kafka.*(0.4.13|0.4.14)" | grep -v "REPOSITORY" | awk '{print $1":" $2}'); do + docker rmi ${i} || true + done } # remove tmp/hfc and hfc-key-store data