JetBrains / teamcity-unity-plugin

TeamCity plugin supports building Unity projects
Apache License 2.0
81 stars 38 forks source link

How do I configure the artifacts build output for WebGL #60

Open MeltdownInteractive opened 3 years ago

MeltdownInteractive commented 3 years ago

I am using a self-hosted TeamCity agent, running the Unity plugin.

I have WebGL as the build target, but I cannot for the life of me figure out how to configure the build output to go into a \builds path off the project root.

I can't browse in the TeamCity dialog 'Select files to be published as artifacts', for the artifacts to include, as I don't see the build artifacts listed anywhere in the dialog, just regular folders from my project.

I've done a complete file search on all the TeamCity directories on my PC, looking for the build output, but don't see anything.

I feel like I'm missing some configuration step somewhere, stating where the output of the WebGL build should go to, but I've tried setting the 'artifact paths' setting to */ => build But I get an error that there were too many artifacts.

I then tried setting the 'artifact paths' setting to just getting my .html file to be exported build/*.html But I still don't have any artifacts once my build has been completed.

Thanks

AaronZurawski commented 3 years ago

The build output is not something the Unity runner plugin handles as it doesn't handle building your project, only opening Unity.

You would have your function that you use to build your project control where the build is output and provide that function to the Unity runner's Execute method field.

For most basic configurations, your function will want to call BuildPipeline.BuildPlayer which takes a BuildPlayerOptions struct that has a locationPathName field that you can use to set the output path.

So an example for you might look like this:

namespace BuildUtilities
{
    public static void BuildWebGL()
    {
        BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
        buildPlayerOptions.scenes = new[] { "Assets/Scenes/MyFirstScene.unity", "Assets/Scenes/MySecondScene.unity" };
        buildPlayerOptions.locationPathName = "build";
        buildPlayerOptions.target = BuildTarget.WebGL;
        buildPlayerOptions.options = BuildOptions.None;

        BuildPipeline.BuildPlayer(buildPlayerOptions);
    }
}

This is only a sample, I would recommend reading Unity's EditorBuildSettings.scenes and transform that into the scene paths that BuildPlayer takes so that your builds remain in sync with the editor.

You would then add BuildUtilities.BuildWebGL to the Execute method field in the runner configuration, and have your artifact paths contain something like build/**/* => MyWebGLBuild.zip if you wanted TeamCity to zip the folder output for you.