SSH keys aren't being used for custom Unity packages

Our Unity project uses SSH to pull down some packages from git: https://docs.unity3d.com/Manual/upm-git.html#Git-SSH

I've added a key on the build machine to the SSH agent and when opening the project on the build agent or running batch mode locally via command line, everything works fine, but when trying to create a build from TeamCity using the Unity build step the build fails with the error:

The SSH key used to pull the repo via VCS is the same key that exists on the build machine, and I've tried initializing an agent and adding the SSH key manually through powershell in another step with no luck.

Any help would be really appreciated.

0
9 comments
Hello Janek,

Did you try adding the host to the 'known_hosts' file on the agent?

See the following link for more details:

https://stackoverflow.com/a/13364116
0

Hey Mikhail,

It's present and added on the build machine (otherwise we wouldn't be able to open the project locally and pull down packages) does it need to be added separately to the build agent itself in any way?

0
Hi Janek,

No, I meant the agent machine, not the agent process itself.

Please provide the entire build log downloaded from the UI. You can upload it here: https://uploads.jetbrains.com. Let me know the upload ID once done.
0

Yeah unless I'm misunderstanding the agent machine has no SSH problems and itself can connect, only when executed via TC do we have any issues.

Here's the ID: 2023_02_17_FK1jhWQxvSFFowrGv7dGY7

Let me know if there's anything else I can provide

0
Hi Janek,
 
I checked with the Dev team. According to them, the Unity plugin starts the Unity process with the corresponding parameters. The plugin doesn't work directly with the SSH agent and its configuration. The Unity process itself also doesn't know anything about the SSH agent. It just uses the environment it works in. So when the Unity process works with external git repositories via the SSH protocol, the environment should be configured beforehand, see https://docs.unity3d.com/Manual/upm-git.html#Git-SSH:~:text=Authenticating%20with%20SSH.
 
In general, the error implies two possible scenarios. Either the host the Unity process tries to access is missing in the known_hosts file, or the key itself is incorrect. In your case, since you mentioned that the host is present in known_hosts, we can assume that the Unity process is working with a different SSH config. The SSH config can be defined on two different levels: user and global. On Windows, I believe it should be located in C:\Users\username\.ssh and C:\ProgramData\ssh accordingly. The target host should be present in the known_hosts file for the user that runs the TeamCity agent. Could you please double-check that?
 
Please also try running the same step outside of TeamCity locally on the same agent under the same user and let me know whether the command fails or succeeds:
C:\Program Files\Unity\Hub\Editor\2021.3.18f1\Editor\Unity.exe -batchmode -projectPath ./ -executeMethod TileBakeDataBuilder.TileBake -quit -logFile -
0

Hi Mikhail,

I've tried what you've suggested and unfortunately still no luck. The ssh keys/known hosts exist in both the user level and the global level. I've also tried adding the ssh key via the `nt authority/system` user, this still didn't fix the issue.

As mentioned above running the step locally succeeds with no issues.  

0
Hi Janek,

Just to confirm, did you try using the same command line that is used in the build step to start the step locally as I suggested in my previous message? Did it succeed?
0

I did try it, it worked locally.

0

Hi Janek,

Could you please attach the log with the output from the CLI execution of the above-mentioned command? Just in case, the command should be executed on the same machine where the agent runs and using the same user that runs the agent. Not on your local workstation. 

0

Please sign in to leave a comment.