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

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?


5 answers

1 accepted

Here is something that worked for me:

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

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

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

For bamboo.. successful exit == 0

We have created this as a bug that can be tracked at

0 vote

What if you run your script with no input stream?

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

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

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,816 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you