aboutsummaryrefslogtreecommitdiff
path: root/jenkins/setup_adb.sh
blob: b3ff2877bdba39798626ee504466e93a75b2a99f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash

# Setup ssh connection with port forwarding for adb client on jenkins slave
# to connect to adb server on lab machine which has nexus devices connected.
#
# The script expects ANDROID_ADB_SERVER_PORT and ADB_VERSION set depending on
# the build (i.e Tip vs Stable). We have 2 version of adb servers stored on the
# lab machine and the right version of adb needs to be started or else the server
# will get killed if there is a mismatch between client and server.
#
# nexus-config file has the following information
# FLOUNDER (serial_id)
# BULLHEAD (serial_id)
# REMOTE_PORT (port number to which we need to ssh into)
# SERVER_IPADDRESS (Server ip address to connect to)

set -u

# shellcheck disable=SC2086
: ${ANDROID_ADB_SERVER_PORT:=5037}

ssh-keyscan -p "${REMOTE_PORT}" "${SERVER_IPADDRESS}"  > ~/.ssh/known_hosts

# Kill all adb servers on lab machine or else nexus devices won't be visible to new server.
ssh nexus-machine killall adb-stable adb-tip

# Start the right version of adb server.
ssh nexus-machine "${ADB_VERSION}" -P "${ANDROID_ADB_SERVER_PORT}" start-server

# Setup port forwarding connection.
ssh -L "${ANDROID_ADB_SERVER_PORT}:127.0.0.1:${ANDROID_ADB_SERVER_PORT}" nexus-machine -f -N