blob: 513d4a35fb669d1345ada6c60348aec6f38d8241 [file] [log] [blame]
Jan Tattermusch083466f2015-06-03 13:17:40 -07001#!/bin/bash
2# Copyright 2015, Google Inc.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# * Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above
12# copyright notice, this list of conditions and the following disclaimer
13# in the documentation and/or other materials provided with the
14# distribution.
15# * Neither the name of Google Inc. nor the names of its
16# contributors may be used to endorse or promote products derived from
17# this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jan Tattermusch8fa8c042015-06-03 14:02:07 -070030#
Jan Tattermusch083466f2015-06-03 13:17:40 -070031# This script is invoked by Jenkins and triggers a test run based on
32# env variable settings.
Jan Tattermusch8fa8c042015-06-03 14:02:07 -070033#
34# To prevent cygwin bash complaining about empty lines ending with \r
35# we set the igncr option. The option doesn't exist on Linux, so we fallback
36# to just 'set -ex' there.
37# NOTE: No empty lines should appear in this file before igncr is set!
38set -ex -o igncr || set -ex
Jan Tattermusch083466f2015-06-03 13:17:40 -070039
40if [ "$platform" == "linux" ]
41then
42 echo "building $language on Linux"
43
Nicolas "Pixel" Noble964f9552015-06-25 02:01:27 +020044 cd `dirname $0`/../..
45 git_root=`pwd`
46 cd -
47
Jan Tattermusch118e3312015-06-17 11:40:21 -070048 # Use image name based on Dockerfile checksum
49 DOCKER_IMAGE_NAME=grpc_jenkins_slave_`sha1sum tools/jenkins/grpc_jenkins_slave/Dockerfile | cut -f1 -d\ `
50
51 # Make sure docker image has been built. Should be instantaneous if so.
52 docker build -t $DOCKER_IMAGE_NAME tools/jenkins/grpc_jenkins_slave
53
Jan Tattermuschbc17b3f2015-06-09 08:22:51 -070054 if [ "$ghprbPullId" != "" ]
55 then
56 # if we are building a pull request, grab corresponding refs.
Jan Tattermuschc3dd3bf2015-06-12 09:18:49 -070057 FETCH_PULL_REQUEST_CMD="&& git fetch $GIT_URL refs/pull/$ghprbPullId/merge refs/pull/$ghprbPullId/head"
Jan Tattermuschbc17b3f2015-06-09 08:22:51 -070058 fi
59
Jan Tattermusch0ee84dc2015-06-12 11:22:49 -070060 # Make sure the CID file is gone.
61 rm -f docker.cid
62
Jan Tattermusch083466f2015-06-03 13:17:40 -070063 # Run tests inside docker
Nicolas "Pixel" Noble964f9552015-06-25 02:01:27 +020064 docker run \
65 -e "config=$config" \
66 -e "language=$language" \
67 -i \
68 -v "$git_root:/var/local/jenkins/grpc" \
69 --cidfile=docker.cid \
70 $DOCKER_IMAGE_NAME \
71 bash -l /var/local/jenkins/grpc/tools/jenkins/docker_run_jenkins.sh || DOCKER_FAILED="true"
Jan Tattermusch0ee84dc2015-06-12 11:22:49 -070072
73 DOCKER_CID=`cat docker.cid`
Nicolas "Pixel" Noble964f9552015-06-25 02:01:27 +020074 docker kill $DOCKER_CID
Jan Tattermusch0ee84dc2015-06-12 11:22:49 -070075 if [ "$DOCKER_FAILED" == "" ]
76 then
77 echo "Docker finished successfully, deleting the container $DOCKER_CID"
78 docker rm $DOCKER_CID
79 else
80 echo "Docker exited with failure, keeping container $DOCKER_CID."
Jan Tattermuscheaa52162015-06-17 12:26:32 -070081 echo "You can SSH to the worker and use 'docker commit CID YOUR_IMAGE_NAME' and 'docker run -i -t YOUR_IMAGE_NAME bash' to debug the problem."
Jan Tattermusch04b28e72015-06-15 22:06:41 -070082 exit 1
Jan Tattermusch0ee84dc2015-06-12 11:22:49 -070083 fi
84
Jan Tattermusch083466f2015-06-03 13:17:40 -070085elif [ "$platform" == "windows" ]
86then
87 echo "building $language on Windows"
88
Jan Tattermuscha959e642015-06-03 16:32:13 -070089 # Prevent msbuild from picking up "platform" env variable, which would break the build
90 unset platform
91
Jan Tattermusch083466f2015-06-03 13:17:40 -070092 # TODO(jtattermusch): integrate nuget restore in a nicer way.
93 /cygdrive/c/nuget/nuget.exe restore vsprojects/grpc.sln
94 /cygdrive/c/nuget/nuget.exe restore src/csharp/Grpc.sln
95
96 python tools/run_tests/run_tests.py -t -l $language
97else
98 echo "Unknown platform $platform"
99 exit 1
100fi