Fix check of Jenkins job name
[ovsnfv.git] / ci / buildovs.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Red Hat Inc. and others.
4 # therbert@redhat.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # Check to verify that I am being run by Jenkins CI.
12
13 if [ -z ${WORKSPACE+1} ]; then
14     # We are not being run by Jenkins.
15     export WORKSPACE=$HOME/opnfv/ovsnfv
16 fi
17
18
19 if [ -z ${OVSTAG+1} ]; then
20     export TAG=master
21 else
22     export TAG=$OVSTAG
23 fi
24
25 export DATE=`date +%Y-%m-%d`
26
27 export BUILD_BASE=$WORKSPACE/build
28
29
30
31 if [ ! -d $BUILD_BASE ]
32 then
33     mkdir -p $BUILD_BASE
34 fi
35
36 if [ ! -f $BUILD_BASE/config ]; then
37     touch $BUILD_BASE/config
38 fi
39
40 export PATH=$PATH:$WORKSPACE/ci:$BUILD_BASE
41
42 source $BUILD_BASE/config
43
44 cd $BUILD_BASE
45 export TOPDIR=$BUILD_BASE
46
47 # build variables
48
49 export TMP_RELEASE_DIR=$TOPDIR/release
50 export CACHE_DIR=$TOPDIR/cache
51 export TMPDIR=$TOPDIR/scratch
52 export RPMDIR=$TOPDIR/rpmbuild
53
54 echo "--------------------------------------------------"
55 echo "Build OVS RPM from upstream git $TAG"
56 echo
57
58 mkdir -p $RPMDIR/RPMS
59 mkdir -p $RPMDIR/SOURCES
60 mkdir -p $RPMDIR/SPECS
61 mkdir -p $RPMDIR/SRPMS
62
63 if [ ! -d $TMP_RELEASE_DIR ]
64 then
65     mkdir -p $TMP_RELEASE_DIR
66 fi
67
68 # Centos build server should support the following build prerequisites
69
70 # yum install gcc make python-devel openssl-devel kernel-devel graphviz \
71 # kernel-debug-devel autoconf automake rpm-build redhat-rpm-config \
72 # libtool
73
74 if [ -d $TMPDIR ]
75 then
76     rm -rf $TMPDIR
77 fi
78
79 mkdir $TMPDIR
80
81 cd $TMPDIR
82
83 echo "---------------------"
84 echo "Clone git repo $TAG"
85 echo
86 git clone https://github.com/openvswitch/ovs.git
87
88 cd ovs
89 echo "--------------------"
90 echo "Checkout OVS $TAG"
91 echo
92 if [[ ! "$TAG" =~ "master" ]]; then
93     git checkout $TAG
94 fi
95 ./boot.sh
96 ./configure
97 echo "--------------------"
98 echo "Make OVS $TAG"
99 echo
100 make
101 #
102 # Get version for master
103 #
104 echo "--------------------"
105 echo "Get OVS version for $TAG"
106 echo
107 if [[ "$TAG" =~ "master" ]]; then
108     v=$($TMPDIR/ovs/utilities/ovs-vsctl --version | head -1 | cut -d' ' -f4)
109     export VERSION=$v
110 else
111     export VERSION=${TAG:1}
112 fi
113
114 echo "--------------------"
115 echo "OVS version is $VERSION"
116 echo
117 echo "--------------------"
118 echo "Make OVS distribution $TAG"
119 echo
120
121 make dist
122
123 cd $TMPDIR/ovs
124
125 cp openvswitch-$VERSION.tar.gz $TOPDIR/rpmbuild/SOURCES
126 cp openvswitch-$VERSION.tar.gz $TMPDIR
127
128 cd $TMPDIR
129 tar -xzf openvswitch-$VERSION.tar.gz
130
131 cd $TMPDIR/openvswitch-$VERSION
132
133
134 echo "--------------------"
135 echo "Build OVS RPM"
136 echo
137
138 if [ ! -z ${NOCHECK+1} ]; then
139     # Build RPM without checks
140     #
141     rpmbuild -bb --define "_topdir `echo $RPMDIR`" --without check rhel/openvswitch.spec
142 else
143     rpmbuild -bb --define "_topdir `echo $RPMDIR`" rhel/openvswitch.spec
144 fi
145
146 # Once build is done copy product to artifactory.
147
148 echo "---------------------------------------"
149 echo "Copy RPM into $TMP_RELEASE_DIR"
150 echo
151 cp $RPMDIR/RPMS/x86_64/*.rpm $TMP_RELEASE_DIR
152
153 # cleanup
154
155 echo "---------------------------------------"
156 echo "Cleanup $TMP_RELEASE_DIR"
157 echo
158 cd $BUILDDIR
159
160 if [ -d $TMPDIR ]
161 then
162     echo rm -rf $TMPDIR
163     rm -rf $TMPDIR
164 fi
165
166 # copy artifacts.
167
168 if [[ "$JOB_NAME" =~ "daily" ]]; then
169     upload_artifacts.sh
170 fi
171
172 exit 0