Unity3D & Jenkins Part 2 – Job configuration – Webbuild

Now we will create the job that clones the project from Github and creates a build. The job will be trigged from the webhook we configured previously.

Step 1 – Create a unity Build script

You need to create a unity build script inside your unity project. This script will determine buildtargets, name of build etc. This script must be placed in the Editor folder.

Below is an example of the script, with two build targets.

using UnityEngine;
using System.Collections;
using UnityEditor;
using System;
using System.Collections.Generic;

public class BuildScript{

static string[] SCENES = FindEnabledEditorScenes();

static string APP_NAME = "<yourAPPName>";
static string TARGET_DIR = "<YourTargetDir>";

[MenuItem ("Custom/CI/Build Mac OS X")]
static void PerformMacOSXBuild ()
{
string target_dir = APP_NAME + ".app";
GenericBuild(SCENES, TARGET_DIR + "/" + target_dir, BuildTarget.StandaloneOSXIntel,BuildOptions.None);
}

[MenuItem ("Custom/CI/Build Web")]
static void PerformWebBuild ()
{
string target_dir = APP_NAME + ".unity3d";
GenericBuild(SCENES, TARGET_DIR + "/web/" + target_dir, BuildTarget.WebPlayer,BuildOptions.None);
}

private static string[] FindEnabledEditorScenes() {
List&lt;string&gt; EditorScenes = new List&lt;string&gt;();
foreach(EditorBuildSettingsScene scene in EditorBuildSettings.scenes) {
if (!scene.enabled) continue;
EditorScenes.Add(scene.path);
}
return EditorScenes.ToArray();
}

static void GenericBuild(string[] scenes, string target_dir, BuildTarget build_target, BuildOptions build_options)
{
EditorUserBuildSettings.SwitchActiveBuildTarget(build_target);
string res = BuildPipeline.BuildPlayer(scenes,target_dir,build_target,build_options);
if (res.Length &gt; 0) {
throw new Exception("BuildPlayer failure: " + res);
}
}

}

Step two – Creating the job
Press new job, choose a freestyle project with an appropriate name. Then fill-out the sections below with your own data.

Source code management setup

Source code management setup – replace with own github project

unity3DPluginConfig

Plugin configuration- add by pressing “Add build step”

BuildTriggers

Build triggers

And now you are done. Save the job and press build to test it. The next step is to todo a mobile build, which I will add later on.

Advertisements

2 thoughts on “Unity3D & Jenkins Part 2 – Job configuration – Webbuild

  1. Pingback: Unity3D Jenkins 1- Setup Jenkins | Historyline Remake

  2. I would love to see this updated. Specially set up in Linux server (Ubuntu). Struggling to see how to automatically install.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s