Bamboo script task remains In progress even after executing all the commands inside the script body
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
This Knowledge base article explain a scenario where Bamboo script task even after executing all the commands inside the script body is not completing the execution and moving to the other tasks.
Environment
This solution was tested on Bamboo 9.2.7
Diagnosis
While looking at Bamboo build logs we can see that the script task is printing the last message from the script body after all the execution is completed.
build 21-Dec-2023 17:40:30 ##############################################################################
build 21-Dec-2023 17:40:30 # Script execution completed successfully
build 21-Dec-2023 17:40:30 ##############################################################################
At this point the expectation is that the script task should be marked as Complete and Bamboo should start executing the other Tasks in the Job, but the script task remains in Progress and nothing is printed in the Bamboo build logs
After sometime we can see the Bamboo hung build killer kicks in and tries to kill this build.
error 22-Dec-2023 18:40:30 Force Stop build feature is enabled for current plan. Either Bamboo has detected the build has hung or it has been manually stopped.
Cause
The cause of the problem is that while the script task has completed it's execution, the related sub process started by it are still running, hence the script task is not marked as Completed. These sub processes can be identified in the build logs when the Hung build killer event is trigerred, see the example below
Found related process: pid: 13186 ppid: 1 pgid: 19 %cpu: 1.0 %mem: 0.0 cmd: /usr/lib64/google-cloud-sdk/platform/bundledpythonunix/bin/python3
getStackTraceAndKillRelatedProcesses for 1 processes
Executing kill -3 13186
Killing: 13186
Executing kill 13186
In the above example we can see that python3 sub process with PID 13186 is still running after the script task has completed the execution and this sub process was started during the script task execution. The sub process is not letting the script task complete the execution.
Solution
The solution is to kill all the sub process started during the execution of the script task via the inline script body.