Unable to add new Bitbucket linked repositories in Bamboo with error "com.atlassian.bamboo.executor.CancelException: /usr/bin/git could not be started"
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. 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
When adding a new Bitbucket linked repository in Bamboo, the following error can be seen in the User Interface:
com.atlassian.bamboo.executor.CancelException: /usr/bin/git could not be started: command [/usr/bin/git version] failed with code -1. Working directory was [/]. []
Existing linked repositories remain functional.
Environment
Observed on Bamboo 9.6.2, but may be applicable to other supported versions.
Diagnosis
When adding a new Bitbucket linked repository in Bamboo, the following errors can be seen on the page:
New access key is required but could not be added to Bitbucket Server.
com.atlassian.bamboo.executor.CancelException: /usr/bin/git could not be started: command [/usr/bin/git version] failed with code -1. Working directory was [/]. []
When checking the Bamboo logs at <bamboo-home>/logs/atlassian-bamboo.log
, the following error is present:
java.io.IOException: Cannot run program "/GIT/PATH/git": error=0, Failed to exec spawn helper: pid: <PID>, exit value: 1
By checking the Operating System's unattended upgrades log files, there's evidence of an unattended upgrade of the JDK packages:
2024-06-06 06:04:55,151 INFO Packages that will be upgraded: ... openjdk-17-jdk openjdk-17-jdk-headless openjdk-17-jre openjdk-17-jre-headless ...
2024-06-06 06:04:55,151 INFO Writing dpkg log to /var/log/unattended-upgrades/unattended-upgrades-dpkg.log
2024-06-06 06:06:12,998 INFO All upgrades installed
The location of the unattended upgrade logs may vary according to your Operating System. Please validate with a System Administrator.
Example locations:
/var/log/apt/history.log
/var/log/unattended-upgrades/unattended-upgrades-dpkg.log
Cause 1
The cause of this issue is an unattended upgrade of Java that includes changes to the JSpawnHelper tool - a component critical for spawning processes from Java applications. This upgrade, performed without a corresponding restart of the Bamboo service (and any other Java processes), leads to inconsistencies between the Bamboo application's runtime environment and the underlying JDK. Consequently, Bamboo's attempts to invoke Git operations fail due to incompatible changes in the JDK's process handling mechanisms.
Cause 2
The file permissions inside the JAVA_HOME/lib/ and specially the jspawnhelper
tool needs to have executable permission for Bamboo to execute any programs like git, bash etc.
Solution 1
Restart the Bamboo service/process. The immediate resolution involves restarting Bamboo, which allows the application to initialize with the updated JDK, aligning the runtime environment with the upgraded JDK's expectations and capabilities.
Solution 2
Provide executable permission to the files inside JAVA_HOME/lib/ and specially the jspawnhelper
tool eg: 755
You might also ensure that the JAVA_HOME variable is correctly set: Setting JAVA_HOME.
To prevent similar occurrences, it's recommended to review the settings for unattended upgrades, particularly for critical components like the JDK. Ensuring that automatic updates are either carefully managed or that post-upgrade restarts of dependent services are automated can mitigate downtime and functionality issues.