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).

👍

Automatic release

You can automatically release from your CI/CD, to the testing release tracks (Open Testing / Closed Testing) using PleyClient.ReleaseBuild found below. This is great for rapid QA testing and iterating on updates.
Doing this requires Pley SDK 5.4.0 or later (Here).

For safety reasons we do not allow releasing to Production, it has to be done manually from Game manager

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.
PleyClient.ReleaseBuild(int buildNum, PleyReleaseTrack track)This method will publish the given build to the selected release track (PleyReleaseTrack.OpenTesting or PleyReleaseTrack.ClosedTesting)

Example: Building and releasing 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
  6. Release the build to CloseTesting
  7. Done!
static async void BuildAndUploadToPley()
{
    // 1: Retrieve info from the CI enviroment
    var password = Environment.GetEnvironmentVariable("PASSWORD");
    var email = Environment.GetEnvironmentVariable("EMAIL");
    var description = Environment.GetEnvironmentVariable("BUILD_DESCRIPTION");

    // 2: 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);
    }

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

    // 4: 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 an error.");
    }

    // 5: 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);
  
  	// 6: Release the build to CloseTesting
    var releaseRes = await Pley.PleyClient.ReleaseBuild(
        uploadRes.buildNumber,
        Pley.PleyReleaseTrack.ClosedTesting
    );
    if (releaseRes.errorMsg != null)
    {
        throw new Exception(uploadRes.errorMsg);
    }
    UnityEngine.Debug.Log("Release Successful!");
  	
}