【Unity】Jenkins自动打包扩展知识——SVN篇

学习目标:在已有SVN前提上,对SVN的项目进行自动打包

参考资料:

https://blog.csdn.net/nankeyixiao/article/details/79948608

Jenkins触发器时间格式说明

【Unity】Jenkins自动打包入门小结

SVN入门

关于上面的.\LocalSVNRoot/20200210Main是相对于任务文件目录的相对路径,如下所示。

这个文件夹会在构建的时候自动从SVN的地址检出,也就是SVN的一个副本,这个Jenkins任务构建的工程就是这个本地项目!而不是SVN上的项目。

-quit -batchmode -projectPath E:\jenkins\workspace\第二个Jenkins任务SVN\LocalSVNRoot\20200210Main -executeMethod UnityProjectBuilder.CommandLineBuild -logFile JenkinsBuildUnity.log Platform-$Platform BuildPath-$BuildPath

上面的构建字符串肯定是要改的,如何改?关于上面的字符串在我另一篇文章有介绍就不在此阐述了~

【Unity】Jenkins自动打包入门小结

上面链接文章中的C#脚本有更新,如下所示,将其放入Editor文件夹下即可。

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class UnityProjectBuilder
{

    static string[] GetBuildScenes()
    {
        List<string> names = new List<string>();

        foreach (EditorBuildSettingsScene e in EditorBuildSettings.scenes)
        {
            if (e == null)
                continue;

            if (e.enabled)
                names.Add(e.path);
        }
        return names.ToArray();
    }

    /// <summary>
        /// 此方法是从jienkins上接受  数据的 方法
        /// </summary>
    static void CommandLineBuild()
    {
        try
        {

            Debug.Log("Command line build\n------------------\n------------------");
            string[] scenes = GetBuildScenes();
            //string path = @"E:\Unity游戏包\Android\消消乐游戏";//这里的路径是打包的路径, 定义
            string path = GetJenkinsParameter("BuildPath");
            Debug.Log("构建路径:" + path);
            for (int i = 0; i < scenes.Length; ++i)
            {
                Debug.Log(string.Format("Scene[{0}]: \"{1}\"", i, scenes[i]));
            }
            // ProjectPackageEditor.BuildByJenkins(GetJenkinsParameter("Platform"), GetJenkinsParameter("AppID"), GetJenkinsParameter("Version"), GetJenkinsParameter("IPAddress"));
            Debug.Log("Starting Build!");
            Debug.Log(GetJenkinsParameter("Platform"));

            string platform = GetJenkinsParameter("Platform");
            if (platform == "Android")
            {
                Debug.Log("打包Android");
                BuildPipeline.BuildPlayer(scenes, path + ".apk", BuildTarget.Android, BuildOptions.None);
            }
            else if (platform == "IOS")
            {
                //BuildPipeline.BuildPlayer(scenes, path, BuildTarget.iOS, BuildOptions.AcceptExternalModificationsToPlayer);
            }
            else if(platform == "Window")
            {
                Debug.Log("打包Window");
                BuildPipeline.BuildPlayer(scenes, path + ".exe", BuildTarget.StandaloneWindows64, BuildOptions.None);
            }
        }
        catch (Exception err)
        {
            Console.WriteLine("方法F中捕捉到:" + err.Message);
            throw;//重新抛出当前正在由catch块处理的异常err
        }
        finally
        {
            Debug.Log("---------->  I am copying!   <--------------");
        }
    }


    /// <summary>
    ///解释jekins 传输的参数
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    static string GetJenkinsParameter(string name)
    {
        foreach (string arg in Environment.GetCommandLineArgs())
        {
            Debug.Log("arg:" + arg);
            if (arg.StartsWith(name))
            {
                return arg.Split("-"[0])[1];
            }
        }
        return null;
    }
}

构建成功后

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值