There are a few methods available, if you're using gitlab-ci, the easiest method in the current documentation is using gitlab-ci.
Once you've added all required files to your project (mainly .gitlab-ci.yml
), there should be a manual step that can be triggered for activation.
- Visit your project's settings > CI/CD > Variables and add
UNITY_USERNAME
andUNITY_PASSWORD
with your credentials. Make sure to use your Unity3d email address forUNITY_USERNAME
. - Push your first commit to your project and visit CI/CD Pipelines.
- Locate your latest job, there should be a
play
button, click on it and clickget-activation-file
- Wait for the job to run and follow instructions in the console
All you need is docker installed on your machine.
-
Clone this project
-
Pull the docker image and run bash inside, passing Unity username and password to env
hint: you should write this to a shell script and execute the shell script so you don't have your credentials stored in your bash history. Also make sure you use your Unity3d email address for
UNITY_USERNAME
env var.UNITY_VERSION=2020.1.11f1 IMAGE=unityci/editor # https://hub.docker.com/r/unityci/editor IMAGE_VERSION=0.12 # https://github.com/game-ci/docker/releases DOCKER_IMAGE=$IMAGE:$UNITY_VERSION-base-$IMAGE_VERSION docker run -it --rm \ -e "[email protected]" \ -e "UNITY_PASSWORD=example_password" \ -e "TEST_PLATFORM=linux" \ -e "WORKDIR=/root/project" \ -v "$(pwd):/root/project" \ $DOCKER_IMAGE \ bash
If your password contains a
!
, you can escape it like this (example_pass!word
):... -e "UNITY_PASSWORD=example_pass"'!'"word" \ ...
-
In Unity docker container's bash, run once like this, it will try to activate
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \ unity-editor \ -logFile /dev/stdout \ -batchmode \ -nographics \ -username "$UNITY_USERNAME" -password "$UNITY_PASSWORD"
-
Wait for output that looks like this:
LICENSE SYSTEM [2017723 8:6:38] Posting <?xml version="1.0" encoding="UTF-8"?><root><SystemInfo><IsoCode>en</IsoCode><UserName>[...]
If you get the following error:
Can't activate Unity: No sufficient permissions while processing request HTTP error code 401
Make sure your credentials are valid. You may try to disable 2FA in your account and try again. Once done, you should enable 2FA again for security reasons. See #11 for more details.
-
Copy xml content and save as
unity3d.alf
-
Open https://license.unity3d.com/manual and answer questions
-
Upload
unity3d.alf
for manual activation -
Download
Unity_v2018.x.ulf
(Unity_v2019.x.ulf
for 2019 versions) -
Copy the content of
Unity_v2018.x.ulf
license file to your CI's environment variableUNITY_LICENSE
. Note: if you are doing this on Windows, chances are the line endings will be wrong as explained here. Luckily for you,.gitlab-ci.yml
of the example project solves this by removing\r
character from the ENV variable so you'll be alright.gitlab-ci.yml
will then place theUNITY_LICENSE
to the right place before running tests or creating the builds.
-
Clone this project
-
Pull the docker image and run bash inside, passing Unity username and password to env
hint: you should write this to a shell script and execute the shell script so you don't have your credentials stored in your bash history. Also make sure you use your Unity3d email address for
UNITY_USERNAME
env var.UNITY_VERSION=2020.1.11f1 IMAGE=unityci/editor # https://hub.docker.com/r/unityci/editor IMAGE_VERSION=0.12 # https://github.com/game-ci/docker/releases DOCKER_IMAGE=$IMAGE:$UNITY_VERSION-base-$IMAGE_VERSION docker run -it --rm \ -e "[email protected]" \ -e "UNITY_PASSWORD=example_password" \ -e "UNITY_SERIAL=AN-EXAM-PLE-SERIA-LKEY-1234" \ -e "TEST_PLATFORM=linux" \ -e "WORKDIR=/root/project" \ -v "$(pwd):/root/project" \ $DOCKER_IMAGE \ bash
-
In Unity docker container's bash, run once like this, it will try to activate
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \ unity-editor \ -logFile /dev/stdout \ -batchmode \ -nographics \ -username "$UNITY_USERNAME" -password "$UNITY_PASSWORD" -serial "$UNITY_SERIAL"
-
Wait for the command to finish without errors
-
Obtain the contents of the license file by running
cat /root/.local/share/unity3d/Unity/Unity_lic.ulf
-
Copy the content to your CI's environment variable
UNITY_LICENSE
. Note: if you are doing this on windows, chances are the line endings will be wrong as explained here. Luckily for you,.gitlab-ci.yml
solves this by removing\r
character from the env variable so you'll be alright.gitlab-ci.yml
will then place theUNITY_LICENSE
to the right place before running tests or creating the builds.