Android CI with Atlassian Bamboo
Asked Answered
P

2

7

Does anyone have any good resources for setting up Bamboo to do CI with Android projects? I have mine setup to pull source and compile it with ant. But I would love to know how to setup JUnit tests, where the tests are in a separate project.

Thanks

Primrose answered 12/9, 2014 at 2:54 Comment(3)
Could you share guideline to build Android project using gradle here.Mendes
We installed the JFrog Artifactory plugin into bamboo, it has a build gradle task. You don't need to use JFrog to use. You can then just say the task name under tasks type "clean assembleDebug"Primrose
That I have tried but something going wrong. Last time when I tried this, at least build was starting and throwing failure output, but this time nothing happening. Let me check my side, will revert back you shortly.Mendes
P
2

I have figured out how to do it using Bamboo CI and new Android Studio projects with gradle. Bamboo does not have nice drop in tasks yet but you can leverage the script runner to do it. We setup our basic build tasks as follows:

Source Code Checkout. Script task:

  • Script Location: Inline
  • Script Body: gradlew.bat assembleDebug test (our Bamboo server is Windows so we use the bat file, linux use the ./gradlew assembleDebug test command)

Then we add a final task of JUnit parser, and we use the result directory line of: **/test-results/debug/*.xml

As for testing we use Robolectric Gradle tests, which generate JUnit test results.

I hope this helps anyone else who is looking into how to setup Bamboo with Android, hopefully they will add support one day like they do for .NET where its just a single task that builds and tests. The script command feels kind of a hack.

If someone is looking for Ant style tests, I can share that too but hopefully by now everyone has moved to Android Studio from eclipse. I will say the steps required for Ant and Instrumentation take a lot more time to setup and I had to use an emulator running on the server to do the tests.

Primrose answered 17/7, 2015 at 17:14 Comment(2)
My task is looking for test reports outside repository, like this: Could not find test result reports in the /Users/<user>/bamboo-agent-home/xml-data/build-dir/<bamboo_pbuild_name> directoryLingcod
This only works if one device is connected or an emulator is allready started.Hoop
J
0

In addition to using Bamboo to build the APK for my Android project, I also wanted to use Bamboo to run the JUnit based tests against an Android emulator. After quite a bit of "trial and error" primarily around finding a reliable way to start and stop the Android emulator, here is what I came up with for my Bamboo build plan. See Bamboo waits for script task to terminate, although it is run in the background for additional background information regarding why I take the approach described below.

My Bamboo plan has one stage with two jobs. The jobs run using two agents that execute on the same system. Both jobs start and run in parallel. One job starts the Android emulator using the Android SDK emulator command. The other job waits for the emulator to start, builds the mobile app, runs the tests against the emulator and then stops the running emulator using a final task that is always executed even if a previous task in the build job fails.

The emulator job does get "stuck" after starting the emulator because it is waiting for the emulator process to finish. When the build job runs, the final task in the build job stops the emulator which causes the emulator job to finish because the emulator process is no longer running.

Here are the key task details for the build job:

First task is a script task that waits for the emulator to start. The adb -s command below will fail causing this task to fail if the emulator failed to start.

echo "Waiting 60 seconds for the Android emulator to start"
sleep 60
echo "See if Emulator is up and running"
${bamboo.ANDROID_HOME}/platform-tools/adb -s emulator-5554 shell getprop dev.bootcomplete

The second and third tasks check out the source and build the app using Gradle. The build runs the JUnit tests against the running emulator.

The fourth task which is configured as a final task is a script task that stops the emulator.

echo "Stopping the Android emulator"
${bamboo.ANDROID_HOME}/platform-tools/adb -s emulator-5554 emu kill
Jaguar answered 21/12, 2015 at 18:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.