Game Tech Tutorial
Published in

Game Tech Tutorial

How to Setup CI/CD Pipeline with Jenkins and Unity Test Runner? (Complete Tutorial)

Continuous Integration and Deployment allow you to have fewer bugs in games to increase your productivity.

With CI/CD, you not only can ensure the game code’s stability in every deployment phase but also can release games on time and within budget. In other words, you won't waste too much time in testing, so you can focus on creating interesting features to attract players.

However, it’s hard to find a complete tutorial to build CI/CD pipelines with Jenkins and Unity Test Runner.

This tutorial will guide you to set up your own CI/CD pipelines on Jenkins with Unity Test Runner from the ground up to improve your work efficiency.


Getting Started


Install and Setup Jenkins


brew install jenkins-lts


We are not going to use any plugins or 3-Party lib like fastlane to build ios and android because this is easy to debug and learn as a starting porint. And you can fully control to diagnose any error in conolse.

Of course, you can use fastlane in pipeline when needed.

Create Test Runner cases in Unity

Goto your folder → Right Click Mouse → Create → Assembly definition
→ Create PlayMode.asmdef and place it in /Assets/Tests/PlayMode

Setup PlayMode.asmdef as below

Then we will create a Unity Test Runner case as TestGame.cs in /Assets/Tests/PlayMode


using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.UI;
namespace TestGame
public class PlayModeTestGame
bool clicked = false;
public void SetUp()
// Modify this with your first scene in the game UnityEngine.SceneManagement.SceneManager.LoadScene("<Your Game Scene>");
public IEnumerator TestMenu()
var gameObject = new GameObject();
string name = "start"; // Your Button Name
GameObject startButton = GameObject.Find(name);
var setupButton = startButton.GetComponent<Button>();
yield return new WaitForSeconds(2);
}private void Clicked()
clicked = true;


Test Your Unit Test

Next, we expect Jenkins can run the test case when making any changes in a PR.

Let’s start to set up this pipeline.

Setup Slack Message for Jenkins’s pipeline

Since we will integrate Slack messages in the pipeline, we can always be notified by the latest status via the slack message.

Fill in the following

Click Test Connection to check status

Next, we need to create a pipeline to check PR when someone pushes any changes to the source codes. At this moment, this actually will trigger a webhook to notify Jenkins’s pipeline.

Let’s set up the webhook for the PR pipeline.

Create a webhook in Github to notify Jenkins

Payload URL:

http://<user name>:<API Token>@<Jenkins IP>:<Jenkins Port>/job/<Your PR Pipeline Name>/buildWith Parameters?token=<your_toke_name>


http://test-user:1143acc4dd35ceeb678d213162565fb123@ token=mytoken



Our pipelines need customized functions to build Android or iOS in Unity.

Remember that you need to download BuilderUtility.cs and place it in your project’s Editor folder for setting up pipelines.

Create a PR pipeline to build Android

This pipeline will run test cases and build games for Android when making any changes in PR.

Fill in the following

"pull_request": {
"number": 1,
"state": "closed",
"head": {
"ref": "feature/test-pr"

Let’s start to create a PR pipeline.

Modify Pipeline name, Machine’s user Name, Github URL, and Unity Version.

// Pipeline name
def jobName="your-game-pr"
// Machine's user Name
def machine_user_name="your_user_name"
// Your Github URL
def build_repo=""
// Your Unity Version
// Ex: "2020.1.15f2"
def unity_version="<Your unity verison>"
// Distributed URL via
// deploy_gate_token
def deploy_gate_token="<deploy_gate_token>"
// deploy_gate_upload url
def deploy_gate_upload_url="<deploy_group_name>/apps"


First, we need to understand the following functions in the pipeline.

Function: parseJSON is used to parse request payload from Github’s webhook when making any change in PR.

Function: sendSlackMessage can send messages to Slack Channel for reporting any changes.

Then we start to write the pipeline.

1. Initial environment parameters


2. Clean up workspace and clone branch


3. Run Test cases in Unity Test Runner


4. Build Android in mono or IL2CPP


5. Upload App to the Cloud


Lastly, Uncheck Use Groovy Sandbox.

Create a PR pipeline to build iOS

This pipeline is as same as the previous one, so you can copy the previous pipeline and update the following.


Congratulations! You have learned how to create Test cases in Unity Test Runner and set up CI/CD pipelines to build games for Android or iOS.

You can download the PR pipeline here for reference.

I hope this tutorial will be helpful for you to save time building CI/CD pipeline to speed up your workflow.

Thanks for reading.

Next, you can refer below to set up Jenkins with high availability and scalability when needed.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Eric Wei

Eric Wei


Senior Full Stack Engineer & Solution architecture | AWS, GCP, Azure | Cloud, Unity Game Development, SDK, DevOps, and more.