Bamboo Script tasks containing Gradle builds remain in running state

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Bamboo builds remain in a running state when a Script task is configured to run a Gradle build.

Environment

  • This may happen to other versions of Bamboo but it was originally reported in Bamboo 8.2.1.
  • Your plan or deployment project is configured to run a Gradle build using a Script task.

Diagnosis

  • Check the Bamboo build logs to see if you can identify the status of the Gradle build running inside your agent. In the example below we can see that Gradle printed a build failure message to the logs even though the Bamboo build was still in a running state:

    error	24-May-2022 10:09:33	* Try:
    error	24-May-2022 10:09:33	> Run gradle init to create a new Gradle build in this directory.
    error	24-May-2022 10:09:33	> Run with --stacktrace option to get the stack trace.
    error	24-May-2022 10:09:33	> Run with --info or --debug option to get more log output.
    error	24-May-2022 10:09:33	
    error	24-May-2022 10:09:33	* Get more help at https://help.gradle.org
    error	24-May-2022 10:09:33	
    error	24-May-2022 10:09:33	BUILD FAILED in 3s
  • Look for the absence of logs after Gradle reports its build status. There should be nothing else printed in the build logs after the message displayed above.

Cause

Gradle is not sending an exit code and notifying the Bamboo agent of the status of its builds. When a Gradle build is executed from a Script task it runs outside the agent JVM (Java Virtual Machine) i.e. Gradle is executed as an external process. The agent waits for the external Gradle process to finish and sends an exit code back. When there's an exit code you will see a message like the following one in the build logs:

simple	24-May-2022 10:09:34	Failing task since return code of [/var/atlassian/application-data/bamboo/temp/SCRIP-TIC-SCRIP-22-ScriptBuildTask-18198397679276141324.sh] was 1 while expected 0
simple	24-May-2022 10:09:34	Finished task 'task' with result: Failed

This is how Bamboo determines whether a build failed or succeeded. If the external Gradle process does not return an exit code Bamboo cannot determine the status of the build. The Bamboo agent will keep waiting for it and it will look like the build is "stuck" in progress.

Workarounds

1. Inject the exit code from the script task

Modify the Script task running the Gradle build and include an exit code to instruct Bamboo to fail or succeed in the build. The decision on how to evaluate wether to exit 0 or non-zero is up to each developer. For example:

Command1
Command2
exit 0

2. Disable the Gradle daemon

The Gradle Daemon is enabled by default. You can disable the long-lived Gradle daemon via the --no-daemon command-line option, or by adding org.gradle.daemon=false to your gradle.properties file. Disabling the Gradle daemon may produce longer build times as it will need to be initialised on every build, but also guarantees an ephemeral build session. You can find details of other ways to disable (and enable) the Daemon in the link below:


Last modified on Sep 7, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.