Using Cloud Build with Gitlab

I am having some trouble getting Unity Cloud Build access to my project on Gitlab. I added the SSH key that Unity Cloud Build generated for me to the deployment keys on my project, but it still won’t go past that step where it gives me the key.

@Afropenguinn did you figure this out? if so, would you mind sharing your solution?

Yeah, I was using http when I needed to be using SSH. It still doesn’t work though, due to Gitlab not supporting Git LFS through SSH and Unity Cloud Build not supporting Git LFS through HTTP.

Solved, here are the steps.

Let’s assume that:

  • you already have a gitlab account

  • you have a gitlab project

  • you have your gitlab project checked out

  • you’ve added/committed/pushed your Unity project into your gitlab project.

  • you can view your project and its contents on the gitlab project page.

I’ll note that Chrome is not well-supported in Unity’s admin webpages; prefer Firefox.
Also all of this will almost certainly change in time.

Steps to make Unity Build create builds of your project in GitLab:

  • Start Unity

  • Open your project

  • Click in main menu: “Window/Services” or press ctrl-0

  • Set up the Unity Project ID. Create a new one in the chosen (Unity account) organization, or choose an existing Unity Project ID. A list of services are shown.

  • Click Cloud Build or its button which should be in the OFF state

  • Click “Start using Cloud Build”. A “Source Control” config page is shown.

  • Set “Select source control host type” to “GIT”

  • Go back to your GitLab project page in a browser. In the center of the page there’s a text field with the project’s git url. Select “SSH” then click the copy-to-clipboard button. The project’s git url using ssh protocol is now in your clipboard.

  • Back to Unity, paste the clipboard in “Source control hosting url”. Click next.

  • If you have a private project:

  • A page called “Grant Access” may be shown if you have a private project. Unity will generate a unique ssh key. Copy it to your clipboard.

  • Go back to your GitLab project page in a browser.

  • Click “Settings”, then “Repository.” So top menu is “Settings”, sub menu is “Repository”.

  • A page “Deploy Keys” is shown. paste that key into the field “Key”.

  • Enter a meaningful Title, say the name of your project + " Unity SSH key"

  • Click Add Key. If you refresh the page, you’ll see your new key there somewhere after some Ajax-loading-goodness.

  • Back to Unity. Click next.

  • Platform config page is shown.

  • Pick your platform you’d like to build to. Click next.

  • Target setup config page is shown.

  • Credentials page may be shown for some platforms, Android, iOS etc. You might have to enter the same bundle ID as in your build settings.

  • You can set up additional stuff here:

  • If your branch is empty, your gitlab project’s default branch is used. That default is master, but you can override that in gitlab, and/or specify the branch here.

  • “Project Subfolder:” in some projects you may have an extra directory, say C:\Work\AftropenguinnProject\AfropenguinnProjectUnity. In that case if git’s root is C:\Work\AftropenguinnProject then enter “AfropenguinnProjectUnity”

  • “Auto-build:” this will watch your repo for changes and build automatically when new changes are committed. Very useful.

  • Click Build. The “regular” Cloud Build settings are shown. Here you can see the status of builds, kick off new ones, etc.

Hope that helps!

6 Likes

Actually, this issue should be resolved now, as GitLab currently supports git-lfs through SSH.

I’m stuck at the SSH key. GitLab says the fingerprint is already taken… I tried putting it in the deploy keys for the project and no-go. So I tried putting it in my profile/account’s keys and still “fingerprint is already taken”. Any help is appreciated.

This can happen if you have two accounts with the same fingerprint. It’s using a rather short hash, I guess, so it could collide. Generate a new key pair and try again.

Any idea how to generate a new key? Unity’s only displaying the one key (in the editor and the cloud build website).

Nevermind! I only needed to scroll down to see that there was an OLD project where I tried to set up Unity Cloud Build. So it seems that I can only have ONE repo on GitLab with this SSH key and unity cloud build? Or can I add the SSH to my account and then that will filter through to all projects? Not sure that’s ideal though…

You should ideally have one key-pair for each connecting system/account. So all the ones on UCB should be fine sharing a key, added only once on GitLab. A pair per project would get unwieldy :slight_smile:

Then I guess instead of adding it to the Deploy Keys of a project I’d have to add it at a user level? Makes sense, I have my suspicions it won’t work. Not really sure that a pair per project would be unwieldy, I mean we maintain a keystore per project and lots of things per project, but per machine makes sense for SSH keys as long as it actually works.,

A bit late but for the record @Naphier it’s the gitlab ui which is a bit tricky.

You must REGISTER your Deploy Key only once (and REGISTERING the keu automaticaly ADD it to the current project when you fill the form).

To simply ADD a Deploy Key on an other project on your gitlab instance you have to go a bit down, under the key creation form (red arrow on my screenshot) :

Here you will find your previously added unity cloud Key under ‘privately accessible deploy keys’

Then you can enable the key. The key will go into ‘Enabled deploy keys’.

@GaelFG i dont understand why it work, but it work, thanks!!