$ cd $ANDROID_HOME/tools/bin
$ ./avdmanager list avds
--------------------
Available Android Virtual Devices:
Name: testEmulator
Path: /var/lib/jenkins/.android/avd/credit.avd
Target: Google APIs (Google Inc.)
Based on: Android 6.0 (Marshmallow) Tag/ABI: google_apis/x86
--------------------
Jenkins environment configuration
Login to jenkins.
Click on Manage Jenkins from left menu.
Click on Configure System.
As per your configuration add below environment variables.
Name : ANDROID_HOME
Value: /var/lib/android-sdk
Name : PATH
Value: /home/linuxbrew/.linuxbrew/sbin:/home/linuxbrew/.linuxbrew/bin:/var/lib/android-sdk/tools:/var/lib/android-sdk/platform-tools:/var/lib/android-sdk/build-tools
Jenkins job configuration(Execute below script using shell)
# stop adb
adb kill-server
#Start adb
adb start-server
#Start the emulator
$ANDROID_HOME/tools/emulator -avd <DeviceName> -no-window -wipe-data &
EMULATOR_PID=$!
# Wait for Android to finish booting
WAIT_CMD="adb wait-for-device shell getprop init.svc.bootanim"
until $WAIT_CMD | grep -m 1 stopped; do
echo "Waiting..."
sleep 1
done
# Unlock the Lock Screen
adb shell input keyevent 82
# Clear and capture logcat
adb logcat -c
adb logcat > build/logcat.log &
LOGCAT_PID=$!
# Allow “unknown sources” from Terminal without going to Settings App
adb shell settings put global install_non_market_apps 1
# Go to android team project dir
cd /var/lib/jenkins/qa_automation/android_apps/AndroidTeamProject
git checkout -f develop;
git pull origin develop;
./gradlew installStagingDebug;
# Check devices
adb devices;
# Go to testing team project dir
cd ~/qa_automation/test_automation/TesterTeamProject;
mvn clean compile test
# Stop the background processes
kill $LOGCAT_PID
kill $EMULATOR_PID