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. Dismiss Notice

Pre-processing on CloudBuild

Discussion in 'Unity Build Automation' started by PAL9000, Jun 13, 2019.

  1. PAL9000

    PAL9000

    Joined:
    Aug 11, 2017
    Posts:
    17
    Hey,

    On the 'Project Settings/Player/Identification' (CFBundleVersion) screen there is a 'Build' field.

    Is there a pre-processing directive (#CFBundleVersion) that we could use, so that the Cloudbuilder engine would insert its own build number?

    Thanks,
    Ethan
     
  2. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,077
    I've done a similar thing on iOS so the iOS build number becomes the cloud build number:

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3. using UnityEditor.Callbacks;
    4.  
    5. public class IncrementBuildNumber
    6. {
    7.     #if UNITY_CLOUD_BUILD
    8.     public static void PreExport( UnityEngine.CloudBuild.BuildManifestObject manifest )
    9.     {
    10.         string build = manifest.GetValue( "buildNumber" , null );
    11.         PlayerSettings.bundleVersion = "1.0";
    12.         PlayerSettings.iOS.buildNumber = build;
    13.     }
    14.     #endif
    15. }
    Add that code to a IncrementBuildNumber.cs file and put it in the Editor folder. Then on the cloud build config you need to add that function to the Advanced Options (in Pre-Export method):

    upload_2019-6-14_11-36-58.png
     
  3. alan_motionlab

    alan_motionlab

    Joined:
    Nov 27, 2014
    Posts:
    99
    I take that a tiny step further and also use the build number for the main version number as well and use the same for Android as well to make sure the bundle version code is always updated.

    Code (csharp):
    1. string build = manifest.GetValue("buildNumber", null);
    2. PlayerSettings.bundleVersion = $"{PlayerSettings.bundleVersion}.{build}";
    3. PlayerSettings.iOS.buildNumber = build
    4.  
    5. int buildNo = 1;
    6. int.TryParse(build, out buildNo);
    7.  
    8. PlayerSettings.Android.bundleVersionCode = buildNo;
     
    tonemcbride likes this.