Skip to content

Commit e3da220

Browse files
committed
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: I20f9a322eb9f60b648b4b630df2d4565223be916 Signed-off-by: Sambhav Nidamarty <sambhavdutt@gmail.com>
1 parent 33db64e commit e3da220

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

Jenkinsfile

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,35 @@ node ('hyp-x') { // trigger build on x86_64 node
2020
env.PROJECT_DIR = "gopath/src/github.com/hyperledger"
2121
env.GOPATH = "$WORKSPACE/gopath"
2222
env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:${nodeHome}/bin:$PATH"
23-
23+
def jobname = sh(returnStdout: true, script: 'echo ${JOB_NAME} | grep -q "verify" && echo patchset || echo merge').trim()
2424
def failure_stage = "none"
2525
// delete working directory
2626
deleteDir()
2727
stage("Fetch Patchset") { // fetch gerrit refspec on latest commit
2828
try {
29-
dir("${ROOTDIR}"){
29+
if (jobname == "patchset") {
30+
println "$GERRIT_REFSPEC"
31+
println "$GERRIT_BRANCH"
32+
checkout([
33+
$class: 'GitSCM',
34+
branches: [[name: '$GERRIT_REFSPEC']],
35+
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'gopath/src/github.com/hyperledger/$PROJECT'], [$class: 'CheckoutOption', timeout: 10]],
36+
userRemoteConfigs: [[credentialsId: 'hyperledger-jobbuilder', name: 'origin', refspec: '$GERRIT_REFSPEC:$GERRIT_REFSPEC', url: '$GIT_BASE']]])
37+
} else {
38+
// Clone fabric-samples on merge
39+
println "Clone $PROJECT repository"
40+
checkout([
41+
$class: 'GitSCM',
42+
branches: [[name: 'refs/heads/$GERRIT_BRANCH']],
43+
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'gopath/src/github.com/hyperledger/$PROJECT']],
44+
userRemoteConfigs: [[credentialsId: 'hyperledger-jobbuilder', name: 'origin', refspec: '+refs/heads/$GERRIT_BRANCH:refs/remotes/origin/$GERRIT_BRANCH', url: '$GIT_BASE']]])
45+
}
46+
dir("${ROOTDIR}/$PROJECT_DIR/$PROJECT") {
3047
sh '''
31-
[ -e gopath/src/github.com/hyperledger/fabric-samples ] || mkdir -p $PROJECT_DIR
32-
cd $PROJECT_DIR
33-
git clone git://cloud.hyperledger.org/mirror/fabric-samples && cd fabric-samples
34-
git fetch origin "$GERRIT_REFSPEC" && git checkout FETCH_HEAD
48+
# Print last two commit details
49+
echo
50+
git log -n2 --pretty=oneline --abbrev-commit
51+
echo
3552
'''
3653
}
3754
}
@@ -40,7 +57,7 @@ node ('hyp-x') { // trigger build on x86_64 node
4057
currentBuild.result = 'FAILURE'
4158
throw err
4259
}
43-
}
60+
}
4461
// clean environment and get env data
4562
stage("Clean Environment - Get Env Info") {
4663
try {
@@ -56,7 +73,7 @@ node ('hyp-x') { // trigger build on x86_64 node
5673
}
5774

5875
// Pull Third_party Images
59-
stage("Pull third_party images") {
76+
stage("Pull third_party Images") {
6077
// making the output color coded
6178
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
6279
try {
@@ -73,7 +90,7 @@ node ('hyp-x') { // trigger build on x86_64 node
7390
}
7491

7592
// Pull Fabric, fabric-ca Images
76-
stage("Pull Docker images") {
93+
stage("Pull Docker Images") {
7794
// making the output color coded
7895
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
7996
try {
@@ -126,13 +143,13 @@ node ('hyp-x') { // trigger build on x86_64 node
126143
// Archive the artifacts
127144
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log'
128145
// Sends notification to Rocket.Chat jenkins-robot channel
129-
if (env.JOB_NAME == "fabric-samples-merge-byfn") {
146+
if (env.JOB_NAME == "fabric-samples-merge-job") {
130147
if (currentBuild.result == 'FAILURE') { // Other values: SUCCESS, UNSTABLE
131148
rocketSend message: "Build Notification - STATUS: *${currentBuild.result}* - BRANCH: *${env.GERRIT_BRANCH}* - PROJECT: *${env.PROJECT}* - (<${env.BUILD_URL}|Open>)"
132149
}
133150
}
134151
}
135-
// End Try block
152+
// End Timestamps block
136153
}
137154
// End Node block
138155
}

scripts/Jenkins_Scripts/CI_Script.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ function clearContainers () {
5656
function removeUnwantedImages() {
5757

5858
for i in $(docker images | grep none | awk '{print $3}'); do
59-
docker rmi ${i};
59+
docker rmi ${i} || true
6060
done
6161

6262
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
63-
docker rmi ${i};
63+
docker rmi ${i} || true
6464
done
6565
}
6666

@@ -96,10 +96,10 @@ env_Info() {
9696
pgrep -a docker
9797
}
9898

99-
# Pull Thirdparty Docker images (Kafka, couchdb, zookeeper)
99+
# Pull Thirdparty Docker images (kafka, couchdb, zookeeper baseos)
100100
pull_Thirdparty_Images() {
101101
echo "------> BASE_IMAGE_TAG:" $BASE_IMAGE_TAG
102-
for IMAGES in kafka couchdb zookeeper; do
102+
for IMAGES in kafka couchdb zookeeper baseos; do
103103
echo "-----------> Pull $IMAGES image"
104104
echo
105105
docker pull $ORG_NAME-$IMAGES:${BASE_IMAGE_TAG} > /dev/null 2>&1
@@ -108,14 +108,15 @@ pull_Thirdparty_Images() {
108108
exit 1
109109
fi
110110
docker tag $ORG_NAME-$IMAGES:${BASE_IMAGE_TAG} $ORG_NAME-$IMAGES
111+
docker tag $ORG_NAME-$IMAGES:${BASE_IMAGE_TAG} $ORG_NAME-$IMAGES:$VERSION
111112
done
112113
echo
113114
docker images | grep hyperledger/fabric
114115
}
115116
# pull fabric images from nexus
116117
pull_Docker_Images() {
117118
pull_Fabric_CA_Image
118-
for IMAGES in peer orderer tools ccenv; do
119+
for IMAGES in peer orderer tools ccenv nodeenv; do
119120
echo "-----------> pull $IMAGES image"
120121
echo
121122
docker pull $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG > /dev/null 2>&1
@@ -125,6 +126,7 @@ pull_Docker_Images() {
125126
fi
126127
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES
127128
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES:$ARCH-$VERSION
129+
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES:$VERSION
128130
docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG
129131
done
130132
echo

0 commit comments

Comments
 (0)