bat和shell打包unity的exe

参考:
https://blog.csdn.net/qq_37601496/article/details/83991061
https://blog.csdn.net/jcpkwudi/article/details/89521826
https://testerhome.com/topics/20219

双击的bat文件
这个文件也可以直接复制到jekins下执行。

@echo on

set UNITY_PATH="C:\Program Files\Unity\Editor\Unity.exe"
set UNITY_PROJECT_PATH=D:\xxxx
set UNITY_METHOD_NAME=BuilderApk.BuildMyAndroidApk
set UNITY_LOG_PATH=D:\exe\BatunityApk_log.txt

%UNITY_PATH% -quit -batchmode -logFile %UNITY_LOG_PATH% -projectPath %UNITY_PROJECT_PATH% -executeMethod %UNITY_METHOD_NAME% 
echo 4.打包成功
pause
using System.Collections.Generic;
using UnityEditor;

public class BuilderApk : Editor
{
    [MenuItem("BuildApk/BuildMyAndroidApk")]
    public static void BuildMyAndroidApk()
    {
        string outputPath = "D:\\exe\\xx.exe";           //输出的安装包路径目录
        BuildOptions buildOption = BuildOptions.None;
        outputPath = outputPath.Replace('\\', '/');
        BuildPipeline.BuildPlayer(GetBuildScenes(), outputPath, BuildTarget.StandaloneWindows, buildOption);
    }

    /// <summary>
    /// 取得要打包的场景
    /// </summary>
    /// <returns></returns>
    static string[] GetBuildScenes()
    {
        List<string> pathList = new List<string>();
        foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
        {
            if (scene.enabled)
            {
                pathList.Add(scene.path);
            }
        }
        return pathList.ToArray();
    }
}

直接双击的shell脚本:

#!/bin/sh
# unity app path
UNITY_PATH="C:\Program Files\Unity\Editor\Unity.exe"
# project path
PROJ_PATH=D:\xxxx
UNITY_LOG_PATH=D:\exe\BatunityApk_log.txt
 
echo "============== Unity Build APK Begin =============="
"$UNITY_PATH" -projectPath $PROJ_PATH -executeMethod BuilderApk.BuildMyAndroidApk -logFile $UNITY_LOG_PATH -batchMode -quit
 
echo "============== Unity Build APK Finish =============="
exec /bin/bash 

exec /bin/bash 是双击执行,然后等待,不自动退出。
在这里插入图片描述

jekins下的sh脚本书写:
这个和双击的sh脚本,路径的设置上,要家""否则,路径找不到。

# unity app path
UNITY_PATH="C:\Program Files\Unity\Editor\Unity.exe"
# project path
PROJ_PATH="D:\xxxx"
UNITY_LOG_PATH="D:\exe\BatunityApk_log.txt"
 
echo "============== Unity Build APK Begin =============="
"$UNITY_PATH" -projectPath $PROJ_PATH -executeMethod BuilderApk.BuildMyAndroidApk -logFile $UNITY_LOG_PATH -batchMode -quit
 
echo "============== Unity Build APK Finish =============="

还可以直接填写文件执行:

"C:\Program Files\Git\bin\sh.exe" "D:\abc.sh"

当然这要想在windows下让jenkins执行shell文件,还要在这里设置下:
在这里插入图片描述
在这里插入图片描述
这里要先安装git。

©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页