Automate activation pipeline
Situation
It would be very nice to have a way to only fill in username and password and get your hands on a unity_${year}.x.ulf
file directly from the CI in a magic way.
The problem
Sadly, Unity activation system has a few limitations; the whole activation process could be automated, but there is one thing that prevents it from being 100% automated:
When you use a machine with a different IP (another geographic location), The unity team will send you an email for making sure it's really you.
Here's the content of the received email:
title: Security Notice - Verification code for Unity ID
Message:
Hello,
Verification code for your Unity ID is XXXXXX and will be expired in 5 minutes.
You are getting this email because we have noticed you are trying to log in via another geographic location. You can avoid these emails by adding a TFA system to your account by going to id.unity.com.
For security purpose, please do not share your account information to anyone else and thanks for your understanding.
Sincerely,
The Unity Team
Semi automated example
Activation process using docker gableroux/unity3d-activator (difficulty: intermediate)
- Download the artifact which should contain ${activation_file}
- Open a shell in the folder where you downloaded the activation file
- Run these commands (make sure you replace environment variables with the right values):
git clone https://gitlab.com/gableroux/unity3d-activator
cp ./unity3d.alf ./unity3d-activator/
cd ./unity3d-activator
cp .env.example .env
Edit .env
, then
docker-compose run --rm activate
- Locate the newly generated license file in the current folder
- Copy the content of 'Unity_v2019.x.ulf' license file to your CI's environment variable 'UNITY_LICENSE_CONTENT'. (Open your project's parameters > CI/CD > Variables and ad 'UNITY_LICENSE_CONTENT' as the key and paste the content of the license file into the value)"
Automated example
In case you are using your own gitlab-runners which are hosted near you (ie; you have your own gitlab-runner at home, or you're using your personal computer as a gitlab-runner), the following can work:
Here's a gitlab job you can add to the .gitlab-ci.yml
to automate the process of downloading the license file from unity's website:
get-license-file:
stage: get_license
image: gableroux/unity3d-activator:v1.0.1
retry: 2 # this job sometimes fail for unknown reasons, trying it again sometimes help
dependencies:
- get-activation-file
script:
- unity3d-activator
artifacts:
when: always
paths:
- $UNITY_LICENSE_FILE
- debug_images/
expire_in: 10 min # Expiring this as artifacts will contain sensitive data and should not be kept public
This can run after the get-activation-file
. It will do these things:
- POST
$UNITY_ACTIVATION_FILE
to unity's activation form - Download the
ulf
file from unity activation site - Add the downloaded license to artifacts
Once this is done, you have 10 minutes to download the ulf
file, copy the content of the file and add it to UNITY_LICENSE_CONTENT
environment variable in your project's gitlab-ci settings > CI/CD > Variables.
I tried it here: !26 (closed) but quickly hit the Verification code
problem which fails with the following output:
[activator] Directory debug_images is already present.
[activator] Open manual page & wait for login redirect
[activator] Enter credentials
[activator] Click submit
[activator] Wait for license upload form
{ TimeoutError: waiting for selector "#licenseFile" failed: timeout 30000ms exceeded
at new WaitTask (/app/node_modules/puppeteer/lib/DOMWorld.js:561:28)
at DOMWorld._waitForSelectorOrXPath (/app/node_modules/puppeteer/lib/DOMWorld.js:490:22)
at DOMWorld.waitForSelector (/app/node_modules/puppeteer/lib/DOMWorld.js:444:17)
at Frame.waitForSelector (/app/node_modules/puppeteer/lib/FrameManager.js:628:47)
at Frame.<anonymous> (/app/node_modules/puppeteer/lib/helper.js:111:23)
at Page.waitForSelector (/app/node_modules/puppeteer/lib/Page.js:1046:29)
at /app/index.js:50:16
at process._tickCallback (internal/process/next_tick.js:68:7) name: 'TimeoutError' }
Again, above example will only work if the runner is in the same geographic location.
Possible workarounds
- Support Verification code
- Update https://gitlab.com/gableroux/unity3d-activator to support
Verification code
input - Split the job to allow starting a second step manual action and input the
Verification code
with gitlab-ci job variable that can be filled when triggering the job manually
- Update https://gitlab.com/gableroux/unity3d-activator to support
- Enable
tfa
and bypass it- There's probably a way to automate
tfa
process
- There's probably a way to automate
- Do the manual instructions
- Use the unity3d-activator on your own system
Anyway, these workarounds are just overkill, just do the thing on your own system manually or using provided instructions ;) If you feel you have a solution and would like to contribute, you can discuss it here.