Jenkins can automate an Android build you normally start by hand in the Unity Editor. The Docker image fixes Unity and Android SDK, NDK, and JDK versions; Jenkins runs the Editor from the command line in a fresh container to produce an Android App Bundle (AAB). For Unity Personal, the worker keeps login and license state so new containers can reuse it.
1. Prepare the worker
- Use a dedicated Linux Jenkins worker (the machine running the job) with Docker and one executor; the Unity Editor doesn’t need to be installed on its host.
- For Unity 6000.6.7f1, use GameCI’s community Android image
unityci/editor:ubuntu-6000.6.7f1-android-3(not an official Unity image). It includes the Editor and Android tools. The Dockerfile adds tool checks and writable UID 1000 paths; its custom image isharbor.maksonlee.com/library/unity-android-build-env. Pin your registry image by digest in Jenkins. - Install Unity CLI 1.0.0-beta.17 on the worker, verify it against the version manifest, and make it executable. This example mounts it read-only from
/home/administrator/jenkins/unity-cli/1.0.0-beta.17/unity; adapt that path. The Jenkinsfile expects a Vault signing credential.
The bootstrap script keeps HOME (/home/ubuntu), /usr/share/unity3d, and a machine ID on persistent worker storage. Use the same UID/GID 1000 and hostname for activation and builds.
2. Activate Personal once
Set the script’s example state path, CLI path/checksum, image digest, and hostname for your worker, matching the Jenkinsfile. Have the image and CLI available there. Run from the repository root:
bootstrap=Jenkinsfile/unity/math-runner-android-build-in-docker/bootstrap-unity-personal.sh
bash "$bootstrap" init
bash "$bootstrap" login
bash "$bootstrap" activate
bash "$bootstrap" verify
bash "$bootstrap" seallogin asks the account owner to complete browser sign-in. activate passes --accept-eula, so review and accept Unity Personal’s terms before running it. verify checks two fresh Editor containers; seal marks the setup ready.
3. Connect Jenkins
Create a Pipeline from SCM job with Git git@github.com:maksonlee/jenkins-pipelines.git, an SSH credential, branch main, and script path Jenkinsfile/unity/math-runner-android-build-in-docker/Jenkinsfile. The linked Jenkinsfile is a Math Runner example: it checks out a separate project repository and expects a shared library, Vault signing access, and Artifactory. Replace its project Git URL and configure or adapt those integrations.
Set GIT_REF to a full project commit SHA, then supply VERSION_NAME and ANDROID_VERSION_CODE. Normal builds check the saved Unity sign-in and license status before starting the Editor; they don’t activate or return the license. If authorization expires, the job stops at that check.
4. Build the AAB
The example job writes Vault signing values to temporary 0600 files outside the persistent Unity state, mounts them read-only, and removes them after the build. It runs the Editor inside Docker with:
/opt/unity/Editor/Unity -batchmode -nographics -quit -buildTarget Android \
-projectPath /workspace \
-executeMethod MathRunner.Editor.ProjectBuilder.BuildAndroidPlayAab \
-logFile /workspace/Evidence/Checks/Builds/PlayAab/Unity.logBuildAndroidPlayAab belongs to the Math Runner project; Unity doesn’t provide it. Replace it with your own static Editor method that enables App Bundle and ARM64/IL2CPP, reads the version and signing files, calls BuildPipeline.BuildPlayer, and fails on a build error. Update -executeMethod to match.
5. Check and keep the bundle
Check the AAB with bundletool, confirm the package and version, and verify its signature against your upload certificate. Archive it with the source commit and SHA-256. The example job also copies it to Artifactory and downloads it to check the stored file.
