Bamboo fails to connect to Bitbucket Data Center repositories with "ssh: not found"
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
Adding a Bitbucket Data Center repository to Bamboo, or re-saving an existing one, fails with the following error message: exec: ssh: not found.
Builds can also fail to run.
Environment
The solution has been validated in Bamboo 9.6 but may be applicable to other versions.
Diagnosis
In the User Interface, the following error appears when saving the Linked Repository:
New access key is required but could not be added to Bitbucket Server.
<bamboo-install>/temp/bamboo-ssh.2958cbb8.sh: line 2: exec: ssh: not found fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
In the <bamboo-home>/logs/atlassian-bamboo.log
, the following "ssh: not found
" error is present when performing Git operations:
Caused by: com.atlassian.bamboo.plugins.git.GitCommandException: command [/git/bin/git ls-remote ssh://6fb8e7bc-91be-4fc2-943e-2ddaf7c8c451@127.0.0.1:46767/PROJECT/REPOSITORY.git] failed with code 128. Working directory was [/data/Bamboo/atlassian-bamboo-9.6.1/temp]., stderr:
/data/Bamboo/atlassian-bamboo-9.6.1/temp/bamboo-ssh.2958cbb8.sh: line 2: exec: ssh: not found
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Other errors regarding common system tools might be present as well. E.g., error running bash:
2024-06-28 22:14:49,684 WARN [https-jsse-nio-8443-exec-89 url: /plugins/servlet/troubleshooting/view/atst-detect-issues/view; user: USER] [DefaultRuntimeHelper] Failed to spawn a process
java.io.IOException: Cannot run program "bash": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1128) ~[?:?]
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1071) ~[?:?]
Cause
The error is caused by the SSH executable not being found in the PATH environment variable for the user running the Bamboo application. This can occur if the PATH is not correctly defined or if SSH is not installed on the Bamboo server.
Solution
Verify SSH Installation
- Log into the Bamboo server as the same user running the Bamboo application.
- Run which ssh on the terminal to locate the SSH executable. If the command does not return a path, SSH may not be installed.
- If SSH is not installed, install it on the server and restart Bamboo so it picks up the new executable.
- If SSH is installed, proceed to verify the PATH environment variable.
Check and Update the PATH Environment Variable
- Log into the Bamboo server as the same user running the Bamboo application.
- Run echo $PATH on the terminal to view the current PATH variable.
If the path to SSH is not included, you need to add it. This can be done by running, for example, the commands below on the command line running as Bamboo user account, modifying the path according to where SSH is located on your system (typically, SSH is located inside "/usr/bin/" for Linux systems, but the location may vary).
Unixexport PATH=$PATH:/YOUR/PATH/
Windowsset PATH=%PATH%;C:\YOUR\PATH\
After ensuring SSH is installed and the PATH variable is correctly set, restart Bamboo for the changes to take effect.
If the PATH variable is already correctly set
If you verify the PATH variable is already correctly set and the SSH command works from the command line (e.g., ssh -V successfully returns the SSH version) running as the same user as Bamboo:
- Head to Bamboo Administration > System information and look for PATH under the Environment Variables section.
- Verify if the PATH correctly reads the same values as from the command line.
If it's different, please note that environment variables can also be set directly on the <bamboo-install>/bin/setenv file. Review that file to check if PATH was overwritten, and make sure it's correctly set.
When adding directories to the PATH variable, the PATH variable itself must also be re-added with the correct syntax to avoid losing the values already added to the variable. For example,
export PATH=PATH:/YOUR/PATH
would be incorrect because the PATH after the assigning "=" sign is missing the "$" to make it be translated as a variable. For Windows, it must have %PATH%.Unix - correct syntaxexport PATH=$PATH:/YOUR/PATH/
Windows - correct syntaxset PATH=%PATH%;C:\YOUR\PATH\