Build Systems & CI/CD

If you're using a custom build system for making builds in Unity, this is for you.

πŸ“˜

This article is only relevant to you if you are using a custom solution or pipeline for making builds in Unity. It is not a required step for getting started with Pley, but can be a big quality-of-life integration to have!

In this article you'll find (3) ways of integrating:

  1. Adding your build system to the Pley SDK UI
  2. Triggering the Pley SDK from your Build System
  3. Building for Pley without the SDK UI

πŸ“˜

Builds - not releases!

When you upload a build to Pley it'll be handled by the Pley Game Manager. It will not be a release and never be automatically published for your players to play. In the Game Manager you can playtest, configure, and release any builds you have uploaded!

It is on the Pley roadmap to expand our CI/CD-related APIs to automate more of the build/release process.

Adding your Build System to Pley's SDK UI

You can use this to trigger your own build system when pressing any of the "Build" buttons in the Pley Editor Extension.

This is not a requirement for making builds for Pley, it's simply a convenience.

EventsDescription
PleyBuild.CustomBuildThe event that can be used to override the default build pipeline used by Pley. The method provided needs to return a BuildReport, so Pley can store information about the build for easier uploading.
PleyBuild.OnPreBuildThe event that that can be used to run any custom code before a build.

Example:

[InitializeOnLoadMethod]
private static void SetupBuildPipeline()
{
   Pley.PleyBuild.CustomBuild += MyBuildPipeline;
}

private static BuildReport MyBuildPipeline()
{
   BuildPlayerOptions options = new BuildPlayerOptions();

   options.scenes = EditorBuildSettings.scenes
       .Where(x => x.enabled)
       .Select(x => x.path)
       .ToArray();

   options.target = BuildTarget.WebGL;
   options.targetGroup = BuildTargetGroup.WebGL;
   options.options = BuildOptions.ShowBuiltPlayer;
   options.locationPathName = "Builds/WebGL";

   return UnityEditor.BuildPipeline.BuildPlayer(options);
}

Triggering the Pley SDK from your Build System

Useful for example if you want to finish your scripted build process with uploading the build to Pley. This method effectively triggers the "build"-feature of the Pley SDK programmatically.

MethodDescription
PleyBuild.RunFullReport();This method will run through all the reports in Report Window to verify how many required issues exist. Returns the number of problems that need to be fixed before uploading to Pley.
PleyBuild.Build();This method will run the same operation as the Build button provided in the Pley SDK Editor. This will further update the Pley SDK Editor build-cache so you can upload the build without providing a path. Returns BuildReport if the build was not canceled.
PleyBuild.Upload(string description);This method will attempt to upload the latest build, with a description, to Pley if any build exists.
PleyBuild.Upload(string path, string description);This method will attempt to upload a build, with a description, on the provided path to Pley.
PleyBuild.HasBuild();A convenient method to verify if the build cache exists and the directory of the build exists.
This method does not check if all files exist in the build.

Example:

private static void ExampleBuildAndUpload()
{
  var requiredIssues = Pley.PleyBuild.RunFullReport();
  if (requiredIssues > 0)
  {
    	Debug.LogError($"You have {requiredIssues} that needs to be fixed before building for Pley.");
    	return;
  }
  var report = Pley.PleyBuild.Build();
  if (report.summary.result == BuildResult.Succeeded)
  {
  	Pley.PleyBuild.Upload();
  }
}

Ex: Building for Pley without the SDK UI

This example shows how you can upload builds to Pley without using the SDK UI - fixing settings and Pley authentication (login) programmatically.

public async static void BuildPley()
{
  BuildPlayerOptions opts = new BuildPlayerOptions();
  opts.scenes = scenes;
  opts.locationPathName = "Local/Pley/Build";
  opts.target = BuildTarget.WebGL;
  opts.options = BuildOptions.None;
  var report = BuildPipeline.BuildPlayer(opts);

  var password = Environment.GetEnvironmentVariable("PASSWORD");
  var email = Environment.GetEnvironmentVariable("EMAIL");
  var description = Environment.GetEnvironmentVariable("BUILD_DESCRIPTION");

  var loginReq = new Pley.CLI.LoginRequest();
  var loginRes = await loginReq.Login(email, password);
  if (loginRes.Success == false)
  {
    throw new Exception(loginRes.ErrorMessage);
  }
  var uploadReq = new Pley.CLI.UploadBuildRequest();
  var uploadRes = await uploadReq.UploadBuild(report.summary.outputPath, description);
  if (uploadRes.Success == false)
  {
    throw new Exception(uploadRes.ErrorMessage);
  }
}