How to Build for Web with CI/CD

Example script for how to integrate Pley into your build system to automate new updates.

πŸ“˜

Automate your builds!

This article is only relevant to you if you are using a custom build system, pipline or continious integration for making builds in Unity. It is not a required step for getting started with Pley or making web builds, but we highly recommend integrating with your builder.

You can easily upload builds to Pley manually using the Pley SDK Unity UI in Windows > Pley > Pley SDK (documentation).

Triggering the Pley SDK from your Build System

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. Read more here.
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 path, string description);This method will attempt to upload a build, with a description, on the provided path to Pley. If no path is provided, the latest build will be uploaded automatically.

Example: Building for Pley in code

This example shows how you can upload builds to Pley without using the SDK UI. This can be integrated into your build system or CI.

  1. Fetch authentication info, provided by the CI / Builder.
  2. Login to Pley
  3. Verify and Fix Unity Settings
  4. Build Game for Web
  5. Upload the new build to Pley's Game Manager (https://manage.pley.com/)
  6. Done!
static async void BuildAndUploadToPley()
{
    // Retrieve info from the CI enviroment
    var password = Environment.GetEnvironmentVariable("PASSWORD");
    var email = Environment.GetEnvironmentVariable("EMAIL");
    var description = Environment.GetEnvironmentVariable("BUILD_DESCRIPTION");

    // Login into Pley
    var loginRes = await Pley.PleyClient.Login(email, password);
    if (loginRes.ret != Pley.PleyLoginRet.Ok)
    {
        throw new Exception("Not logged in: " + loginRes.ret + loginRes.errMsg);
    }

    // Verify unity settings
    var requiredIssues = Pley.PleyBuild.RunFullReport();
    if (requiredIssues > 0)
    {
        // Can be fix with Pley.Report.FixAllReports();
    	Debug.LogError($"You have {requiredIssues} that needs to be fixed before building for Pley.");
    	return;
    }

    // Build the game
    EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.WebGL, BuildTarget.WebGL);
    var report = Pley.PleyBuild.Build();
    if (report == null || report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded)
    {
        throw new System.Exception("Pley build returned and error");
    }

    // Upload the new build to Pley
    var uploadRes = await Pley.PleyBuild.Upload(report.summary.outputPath, description);
    if (uploadRes.errorMsg != null)
    {
        throw new Exception(uploadRes.errorMsg);
    }
  UnityEngine.Debug.Log("New Pley build uploaded, #" + uploadRes.buildNumber);
}