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).
Uploading and releasing are separate
Upload builds for your team to run directly in Game Manager; no release is needed. Create a release only when you want to update distribution channels in an environment. Releasing to an environment with no channels does not distribute the build.
Existing CI setups targeting Open testing and Closed testing remain supported. The example below uses the existing SDK enum API (Pley SDK 5.4.0 or later); it applies to games that retain those environments. The CLI and SDK are moving toward distribution IDs, but this guide does not assume an ID-based command is already available. See Environments and Testing in Game Manager.
Production publishing through this SDK workflow is performed manually in Game Manager.
Triggering the Pley SDK from your Build System
| Method | Description |
|---|---|
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 legacy environment (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. Omit the release step when you only need uploaded builds for testing in Game Manager.
- Fetch authentication info, provided by the CI / Builder.
- Login to Pley
- Verify and Fix Unity Settings
- Build Game for Web
- Upload the new build to Pley's Game manager
- Optionally release to Closed testing, if that environment has channels to update
- 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: Optional: update channels in the legacy Closed testing environment
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!");
}Updated 4 days ago
