Bamboo waits for script task to terminate, although it is run in the background

Samuel Langlois July 16, 2012

I am trying to setup a build that needs a server to be started first. (It is an Android emulator.)

The emulator is started by a small script, which contains 2 lines:

export PATH=${PATH}:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools

emulator -avd 14 -no-window -noaudio &

When running the script manually, the emulator is started, and returns immediately, thanks to the & at the end of the line.

When I try running this in a Bamboo script task, the emulator starts properly, but the build is stuck there and never reaches the next task.

It does continue as soon as I stop the emulator on the machine.

For some reason, Bamboo is waiting for that process to end.

How could I avoid that?

I tried running the emulator as an inline script as well, but had the same behaviour.

I also tried running it in a bash subprocess, to detach it from the bamboo agent process, but it didn't work either:

bash -c emulator -avd 14 -no-window -noaudio &

It executes on a remote build agent running Linux.

Can you help me?

Thanks!

5 answers

1 accepted

4 votes
Answer accepted
mnsanghvi November 22, 2013

Here is something that worked for me:

nohup ./startup-server </dev/null>/dev/null 2>&1 &

Samuel Langlois September 29, 2015

Yeah, definitely... From my tests, the _nohup_ is actually not necessary, but the rest is. Thanks for the hint.

0 votes
Keith Wedinger December 21, 2015

I too needed to start an Android emulator for running tests during my Android build. This is how I worked around the inability to start the emulator in the background.

My plan has one stage with two jobs. One job starts the emulator using the Android SDK emulator command. The other job waits for the emulator to start, builds the mobile app, runs the tests and then stops the running emulator using a final task that is always executed even if a previous task fails.

The emulator job does get "stuck" after starting the emulator. However, 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 task details for build job:

Script task that does the following:

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 devices
${bamboo.ANDROID_HOME}/platform-tools/adb -s emulator-5554 shell getprop dev.bootcomplete

Tasks to checkout the code from the repo and run the Gradle wrapper script to build the mobile app

Script task configured as a final task that does the following. This task causes the emulator job to finish.

echo "Stopping the Android emulator"
${bamboo.ANDROID_HOME}/platform-tools/adb -s emulator-5554 emu kill
${bamboo.ANDROID_HOME}/platform-tools/adb devices
0 votes
Przemek Bruski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 1, 2012

What if you run your script with no input stream?

bash -c emulator -avd 14 -no-window -noaudio </dev/null &

0 votes
Sultan Maiyaki
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2012

We have created this as a bug that can be tracked at https://jira.atlassian.com/browse/BAM-11887

0 votes
Cameron Ferguson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 16, 2012

have you tried returning out of your script with a successful exit code? That usually halts the script.

For bamboo.. successful exit == 0

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events