Hello!
We would like to make the current git hash visible in our builds. When we build locally, our build script grabs the current git hash and sticks it in a .txt file that we can display at runtime.
It does not seem like our PreExport script works with Unity Cloud Build. Is there a way we can grab this hash and write it to a .txt file right before building?
Here is the code we are running on PreExport.
using UnityEngine;
using System;
public static class PreExport {
public static void DoIt()
{
try
{
Debug.Log("Going to attempt getting git hash from command line.");
// Get the short commit hash of the current branch.
string cmdArguments = "/c git rev-parse --short HEAD";
Debug.Log("About to create ProcessStartInfo.");
var procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", cmdArguments);
Debug.Log("Made the ProcessStartInfo. now setting some properties.");
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
Debug.Log("Properties set. Now making a new Process.");
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
Debug.Log("Assigning ProcessStartInfo to this Process.");
proc.StartInfo = procStartInfo;
Debug.Log("Running git process.");
proc.Start(); // EXCEPTION here?
// Get the output into a string
Debug.Log("Attempting to get output."); // Never runs
string result = proc.StandardOutput.ReadToEnd();
Debug.Log("Got git result: " + result);
}
catch (Exception e)
{
Debug.Log("Unable to run command to get git commit hash. Got exception");
Debug.Log(e); // Does not seem to give us any info.
}
Debug.Log("Unable to get git hash.");
}
}
It seems to give us an error when we try to start the process with proc.Start() . However, I can’t tell what type of exception we are getting. Here is the output from Unity Cloud Build.
1023: [Unity] Going to attempt getting git hash from command line.
1024: [Unity] UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
1025: [Unity] UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
1026: [Unity] UnityEngine.Logger:Log(LogType, Object)
1027: [Unity] UnityEngine.Debug:Log(Object)
1028: [Unity] PreExport:smile:oIt() (at Assets/Editor/PreExport.cs:11)
1029: [Unity] System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
1030: [Unity] UnityEditor.CloudBuild.UnityReflector:CallStaticEditorMethod(String, Boolean, Object[])
1031: [Unity] UnityEditor.CloudBuild.Builder:Build()
1032: [Unity] (Filename: Assets/Editor/PreExport.cs Line: 11)
1033: [Unity] About to create ProcessStartInfo.
1034: [Unity] UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
1035: [Unity] UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
1036: [Unity] UnityEngine.Logger:Log(LogType, Object)
1037: [Unity] UnityEngine.Debug:Log(Object)
1038: [Unity] PreExport:smile:oIt() (at Assets/Editor/PreExport.cs:14)
1039: [Unity] System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
1040: [Unity] UnityEditor.CloudBuild.UnityReflector:CallStaticEditorMethod(String, Boolean, Object[])
1041: [Unity] UnityEditor.CloudBuild.Builder:Build()
1042: [Unity] (Filename: Assets/Editor/PreExport.cs Line: 14)
1043: [Unity] Made the ProcessStartInfo. now setting some properties.
1044: [Unity] UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
1045: [Unity] UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
1046: [Unity] UnityEngine.Logger:Log(LogType, Object)
1047: [Unity] UnityEngine.Debug:Log(Object)
1048: [Unity] PreExport:smile:oIt() (at Assets/Editor/PreExport.cs:16)
1049: [Unity] System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
1050: [Unity] UnityEditor.CloudBuild.UnityReflector:CallStaticEditorMethod(String, Boolean, Object[])
1051: [Unity] UnityEditor.CloudBuild.Builder:Build()
1052: [Unity] (Filename: Assets/Editor/PreExport.cs Line: 16)
1053: [Unity] Properties set. Now making a new Process.
1054: [Unity] UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
1055: [Unity] UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
1056: [Unity] UnityEngine.Logger:Log(LogType, Object)
1057: [Unity] UnityEngine.Debug:Log(Object)
1058: [Unity] PreExport:smile:oIt() (at Assets/Editor/PreExport.cs:24)
1059: [Unity] System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
1060: [Unity] UnityEditor.CloudBuild.UnityReflector:CallStaticEditorMethod(String, Boolean, Object[])
1061: [Unity] UnityEditor.CloudBuild.Builder:Build()
1062: [Unity] (Filename: Assets/Editor/PreExport.cs Line: 24)
1063: [Unity] Assigning ProcessStartInfo to this Process.
1064: [Unity] UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
1065: [Unity] UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
1066: [Unity] UnityEngine.Logger:Log(LogType, Object)
1067: [Unity] UnityEngine.Debug:Log(Object)
1068: [Unity] PreExport:smile:oIt() (at Assets/Editor/PreExport.cs:27)
1069: [Unity] System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
1070: [Unity] UnityEditor.CloudBuild.UnityReflector:CallStaticEditorMethod(String, Boolean, Object[])
1071: [Unity] UnityEditor.CloudBuild.Builder:Build()
1072: [Unity] (Filename: Assets/Editor/PreExport.cs Line: 27)
1073: [Unity] Running git process.
1074: [Unity] UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
1075: [Unity] UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
1076: [Unity] UnityEngine.Logger:Log(LogType, Object)
1077: [Unity] UnityEngine.Debug:Log(Object)
1078: [Unity] PreExport:smile:oIt() (at Assets/Editor/PreExport.cs:29)
1079: [Unity] System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
1080: [Unity] UnityEditor.CloudBuild.UnityReflector:CallStaticEditorMethod(String, Boolean, Object[])
1081: [Unity] UnityEditor.CloudBuild.Builder:Build()
1082: [Unity] (Filename: Assets/Editor/PreExport.cs Line: 29)
1083: [Unity] Unable to run command to get git commit hash. Got exception
1084: [Unity] UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
1085: [Unity] UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
1086: [Unity] UnityEngine.Logger:Log(LogType, Object)
1087: [Unity] UnityEngine.Debug:Log(Object)
1088: [Unity] PreExport:smile:oIt() (at Assets/Editor/PreExport.cs:38)
1089: [Unity] System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
1090: [Unity] UnityEditor.CloudBuild.UnityReflector:CallStaticEditorMethod(String, Boolean, Object[])
1091: [Unity] UnityEditor.CloudBuild.Builder:Build()
1092: [Unity] (Filename: Assets/Editor/PreExport.cs Line: 38)
1093: [Unity] at System.Diagnostics.Process.Start_noshell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in <filename unknown>:0
1094: [Unity] at System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in <filename unknown>:0
1095: [Unity] at System.Diagnostics.Process.Start () [0x00000] in <filename unknown>:0
1096: [Unity] at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:Start ()
1097: [Unity] at PreExport.DoIt () [0x00070] in /BUILD_PATH/garth-smith.githash.default-android/Assets/Editor/PreExport.cs:30
1098: [Unity] UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
1099: [Unity] UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
1100: [Unity] UnityEngine.Logger:Log(LogType, Object)
1101: [Unity] UnityEngine.Debug:Log(Object)
1102: [Unity] PreExport:smile:oIt() (at Assets/Editor/PreExport.cs:39)
1103: [Unity] System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
1104: [Unity] UnityEditor.CloudBuild.UnityReflector:CallStaticEditorMethod(String, Boolean, Object[])
1105: [Unity] UnityEditor.CloudBuild.Builder:Build()
1106: [Unity] (Filename: Assets/Editor/PreExport.cs Line: 39)
1107: [Unity] Unable to get git hash.
1108: [Unity] UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
1109: [Unity] UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
1110: [Unity] UnityEngine.Logger:Log(LogType, Object)
1111: [Unity] UnityEngine.Debug:Log(Object)
1112: [Unity] PreExport:smile:oIt() (at Assets/Editor/PreExport.cs:41)
1113: [Unity] System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
1114: [Unity] UnityEditor.CloudBuild.UnityReflector:CallStaticEditorMethod(String, Boolean, Object[])
1115: [Unity] UnityEditor.CloudBuild.Builder:Build()
1116: [Unity] (Filename: Assets/Editor/PreExport.cs Line: 41)
Is there a way we can have Unity Cloud Build grab the git hash right before building?
