diff --git a/Jenkinsfile b/Jenkinsfile index 9f223c84..970a7c71 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.PROJECT_DIR = "gopath/src/github.com/hyperledger" + def nodeHome = tool 'nodejs-8.9.4' // NodeJs version 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.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 = "${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.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,7 +55,7 @@ node ('hyp-x') { // trigger build on x86_64 node currentBuild.result = 'FAILURE' throw err } - } +} // clean environment and get env data stage("Clean Environment - Get Env Info") { try { @@ -50,9 +68,9 @@ node ('hyp-x') { // trigger build on x86_64 node currentBuild.result = 'FAILURE' throw err } - } + } - // Pull Fabric Images + // Pull Third Party Images (couchdb, zookeeper, kafka) stage("Pull ThirdParty Images") { // making the output color coded wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { @@ -100,16 +118,17 @@ node ('hyp-x') { // trigger build on x86_64 node currentBuild.result = 'FAILURE' 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>)" - } + // Sends notification to Rocket.Chat jenkins-robot channel + if (env.JOB_NAME == "fabric-samples-merge-job") { + if (currentBuild.result == 'FAILURE') { // Other values: SUCCESS, UNSTABLE + rocketSend message: "Build Notification - STATUS: *${currentBuild.result}* - BRANCH: *${env.GERRIT_BRANCH}* - PROJECT: *${env.PROJECT}* - (<${env.BUILD_URL}|Open>)" + } } } // End Timestamps block diff --git a/scripts/Jenkins_Scripts/CI_Script.sh b/scripts/Jenkins_Scripts/CI_Script.sh index ebdcae51..1a305bb4 100755 --- a/scripts/Jenkins_Scripts/CI_Script.sh +++ b/scripts/Jenkins_Scripts/CI_Script.sh @@ -44,21 +44,14 @@ function clearContainers () { } function removeUnwantedImages() { - DOCKER_IMAGES_SNAPSHOTS=$(docker images | grep snapshot | grep -v grep | awk '{print $1":" $2}') - 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}') +for i in $(docker images | grep none | awk '{print $3}'); do + docker rmi ${i} || true +done - 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