Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Pre-export getting access to build number

Discussion in 'Unity Build Automation' started by Endymio, Dec 4, 2015.

  1. Endymio

    Endymio

    Joined:
    Feb 19, 2015
    Posts:
    2
    Hi,

    I'm trying to use the pre-export method and update the PlayerSettings.bundleVersion automatically based on cloud build build number information.

    I first tried to load the manifest file, but based on the logs it seems like the UnityCloudBuildManifest.json is written after the pre-export method is called.

    The documentation at https://build.cloud.unity3d.com/support/guides/advancedfeatures/ says that the method can take an optional BuildManifestObject as parameter, but trying to use method like PreExport(object manifest) just resulted in error that the preExportMethod failed.

    Edit: Still testing this, had another error which probably caused the error message.

    So is there any easy way to get build number (and other information specified in the manifest file) during pre-export method?
     
  2. Endymio

    Endymio

    Joined:
    Feb 19, 2015
    Posts:
    2
    So after trying more cloud build does pass BuildManifestObject as parameter and you can get the build number (and other build information from it). Couldn't find any documentation about the methods for BuildManifestObject which would have saved a lot of experimenting, luckily the uTomate samples at https://github.com/derkork/uTomate-...ts/CloudBuildAPI/Editor/CloudBuildManifest.cs gave a clue about how to access data.

    In case someone else needs to do something similar, the following snippet might help:

    Code (CSharp):
    1.  
    2. #if UNITY_CLOUD_BUILD
    3. using System;
    4. using System.IO;
    5. using UnityEngine;
    6. using UnityEditor;
    7. using System.Collections;
    8. using System.Collections.Generic;
    9.  
    10. public class CloudBuild : MonoBehaviour {
    11.     public static void PreExport(UnityEngine.CloudBuild.BuildManifestObject manifest) {
    12.         PlayerSettings.bundleVersion = String.Format("0.0.{0}", manifest.GetValue("buildNumber", "unknown"));
    13.     }
    14. }
    15. #endif
    16.  
     
  3. dannyd

    dannyd

    Unity Technologies

    Joined:
    Jun 3, 2014
    Posts:
    785
    Glad you got it worked out. We have some docs here for the build manifest, but unfortunately aren't very helpful for using the BuildManifestObject directly. I will get those updates this week to be more useful.