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: Id54da647c1e027627c56153fdfab45ad936ed645
Signed-off-by: Sambhav Nidamarty <sambhavdutt@gmail.com>
This commit is contained in:
Sambhav Nidamarty 2018-12-24 17:47:50 -05:00
parent 5a121b6b27
commit a0d360311d
2 changed files with 45 additions and 33 deletions

59
Jenkinsfile vendored
View file

@ -9,26 +9,44 @@ node ('hyp-x') { // trigger build on x86_64 node
timestamps { timestamps {
try { 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" def nodeHome = tool 'nodejs-8.9.4' // NodeJs version
env.ARCH = "amd64" 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 = 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.VERSION = "$VERSION" // PREV_VERSION from fabric Makefile
env.BASE_IMAGE_VER = sh(returnStdout: true, script: 'cat Makefile | grep BASEIMAGE_RELEASE= | cut -d "=" -f2').trim() 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}" env.BASE_IMAGE_TAG = "${ARCH}-${BASE_IMAGE_VER}" //fabric baseimage version
env.PROJECT_DIR = "gopath/src/github.com/hyperledger"
env.GOPATH = "$WORKSPACE/gopath" 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" def failure_stage = "none"
// delete working directory // delete working directory
deleteDir() deleteDir()
stage("Fetch Patchset") { // fetch gerrit refspec on latest commit stage("Fetch Patchset") { // fetch gerrit refspec on latest commit
try { 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 ''' sh '''
[ -e gopath/src/github.com/hyperledger/fabric-samples ] || mkdir -p $PROJECT_DIR # Print last two commit details
cd $PROJECT_DIR echo
git clone git://cloud.hyperledger.org/mirror/fabric-samples && cd fabric-samples git log -n2 --pretty=oneline --abbrev-commit
git fetch origin "$GERRIT_REFSPEC" && git checkout FETCH_HEAD echo
''' '''
} }
} }
@ -37,7 +55,7 @@ node ('hyp-x') { // trigger build on x86_64 node
currentBuild.result = 'FAILURE' currentBuild.result = 'FAILURE'
throw err throw err
} }
} }
// clean environment and get env data // clean environment and get env data
stage("Clean Environment - Get Env Info") { stage("Clean Environment - Get Env Info") {
try { try {
@ -50,9 +68,9 @@ node ('hyp-x') { // trigger build on x86_64 node
currentBuild.result = 'FAILURE' currentBuild.result = 'FAILURE'
throw err throw err
} }
} }
// Pull Fabric Images // Pull Third Party Images (couchdb, zookeeper, kafka)
stage("Pull ThirdParty Images") { stage("Pull ThirdParty Images") {
// making the output color coded // making the output color coded
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
@ -100,16 +118,17 @@ node ('hyp-x') { // trigger build on x86_64 node
currentBuild.result = 'FAILURE' currentBuild.result = 'FAILURE'
throw err throw err
} }
} }
} }
} finally { } finally {
// Archive the artifacts // Archive the artifacts
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log' archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log'
// Sends notification to Rocket.Chat jenkins-robot channel // 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 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 Timestamps block // End Timestamps block

View file

@ -44,21 +44,14 @@ function clearContainers () {
} }
function removeUnwantedImages() { 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 for i in $(docker images | grep none | awk '{print $3}'); do
echo "---- No snapshot images available for deletion ----" docker rmi ${i} || true
else done
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 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
echo "---- No images available for deletion ----" docker rmi ${i} || true
else done
docker rmi -f $DOCKER_IMAGE_IDS || true
docker images
fi
} }
# remove tmp/hfc and hfc-key-store data # remove tmp/hfc and hfc-key-store data