Nov
18
2021

Run Unity Cloud Build based on Github Commit message using Github Actions

This should had been easy, but unity cloud build system has every secret id hidden in different places and using different names..

  • Create github action (click Actions from your repository)
  • click “Skip this and set up a workflow yourself”
  • copy ready to use script from: https://github.com/unitycoder/UnityCloudBuildGithubActions/blob/main/.github/workflows/main.yml
  • you can modify “branches: [ main ]” if you are not using “main” branch
  • you can modify the required commit messages, for android its the: “#BUILD_ANDROID”
  • you can modify the required commit messages, for ios its the: “#BUILD_IOS”
  • Add secrets to your repo Settings/Secrets
  • collect secret keys from https://dashboard.unity3d.com , If you are invited as a collaborator check https://dashboard.unity3d.com/settings/account/guest-projects
  • Select your cloud project
  • get API_KEY from Devops/Settings page (at API Settings row)
  • PROJECT_ID from Project/Settings page (top bar, settings icon next to project name)
  • ORG_ID from your current dashboard (when viewing project). Looks something like https://dashboard.unity3d.com/organizations/[ORGIDHERE]/projects/..
  • BUILD_TARGET_ID_ANDROID its from DevOps/Config/, those targets that you have deviced there. Click Basic info, its the “Target name:” row, this is actually Build Target ID (but unity named it as “Target name”) and for some reason it defaults to some bad id, like “Default Android”.
  • Repeat for IOS if need it (or remove from script)
  • Note: make it lower case, and replace spaces with – (minus), so “Default Android” becomes “default-android”
  • Note: You can change this id by clicking that blue “edit basic info” link below the opened basic info panel. (not the top panel where it shows “basic info” in title)
  • From “Edit Basic Info” you can now also disable [x] Auto Build (this would build on every commit), and set correct Branch if needed.
  • Now make a commit on main branch, with commit message that includes “#BUILD_ANDROID”, then check from Cloud Build system that build gets started (can take less than 1 minute)

Script info:
// this line checks if commit message contains #BUILD_ANDROID string and only then it runs the curl POST message
if [[ "${{ github.event.commits[0].message }}" == "#BUILD_ANDROID" ]];

Errors:*1
{"error":"Not authorized. User does not have correct permissions to perform this operation."}
Check your Secrets, probably bad ORG_ID.

{"error":"The requested object was not found."}

Check that your secret variables are correct name in the script (if secret is “BUILD_TARGET_ID”, maybe in the script you have “BUILD_TARGET_ID_ANDROID” ?)

*1: You can view log output from Actions/ All Workflows / click the action (has commit message and with green checkmark next to it), then click “build” (this job name was set in the actions script), then click “Run multi-line script”, to open that task log.

Project ID is here
API Key is here
Build Target ID is that string (note: convert to lower case and replace spaces with “-“)
Organization ID is at the URL address (numbers after organizations/)
Can view console log for each action/task (for possible errors)
github secret tokens

5 Comments + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.