基于 Jenkins 的 Unreal Engine 自动化打包流程
Unreal Engine 基于 Jenkins 的自动化打包流程
什么是 Jenkins?
Jenkins 是一款开源的持续集成工具,可用于自动化执行构建、测试和部署任务。通过 Jenkins 可以实现:
定时/触发式构建
多平台打包(Windows/Android/iOS)
版本控制集成(SVN/Git)
构建产物归档
环境准备
1. 安装 Jenkins
# Mac 使用 Homebrew 安装
brew install jenkins-lts
# Windows 下载安装包
https://www.jenkins.io/download/
2. 配置 Unreal 环境
# 全局工具配置
Jenkins > Manage Jenkins > Global Tool Configuration
- Unreal Engine Path: D:/UE_5.2/Engine
- Project Path: D:/Projects/MyUnrealProject
3. 安装必要插件
1. Git Plugin(版本控制)
2. Pipeline(流水线脚本)
3. Credentials Plugin(凭据管理)
4. Email Extension(邮件通知)
构建配置
1. 创建 Pipeline 项目
pipeline {
agent any
parameters {
choice(name: 'PLATFORM', choices: ['Win64', 'Android', 'IOS'], description: '目标平台')
string(name: 'VERSION', defaultValue: '1.0.0', description: '版本号')
}
stages {
stage('Checkout') {
steps {
git branch: 'main',
url: 'https://github.com/yourproject.git'
}
}
stage('Build') {
steps {
bat """
D:/UE_5.2/Engine/Build/BatchFiles/RunUAT.bat
BuildCookRun
-project="D:/Projects/MyUnrealProject/MyProject.uproject"
-platform=%PLATFORM%
-clientconfig=Shipping
-build
"""
}
}
stage('Archive') {
steps {
archiveArtifacts artifacts: 'Build/**/*.zip',
onlyIfSuccessful: true
}
}
}
post {
always {
emailext body: '构建结果:${currentBuild.result}',
subject: 'Unreal 构建通知',
to: 'team@company.com'
}
}
}
2. 参数说明
参数 说明
-BuildCookRun 执行完整构建流程
-platform 目标平台(Win64/Android/IOS)
-clientconfig 构建配置(Debug/Development/Shipping)
-stage 包含的构建阶段
-pak 生成 Pak 文件
-archive 输出目录
进阶配置
1. 版本号自动生成
# GenerateVersion.py
import datetime
version = f"{datetime.datetime.now():%Y.%m.%d.%H%M}"
with open("Version.txt", "w") as f:
f.write(version)
2. 多平台构建矩阵
matrix {
axes {
axis {
name 'PLATFORM'
values 'Win64', 'Android', 'IOS'
}
}
stages {
stage('Build') {
steps {
// 使用相同的构建命令
}
}
}
}
3. 构建后自动化测试
RunUAT.bat RunUnreal
-project="%PROJECT_PATH%"
-test="MyTestCommand"
-report="TestResults.xml"
常见问题排查
构建超时
在 Jenkinsfile 中添加超时设置:
timeout(time: 60, unit: 'MINUTES')
Shader 编译错误
添加清理步骤:
rd /s /q "DerivedDataCache"
rd /s /q "Saved"
磁盘空间不足
配置构建保留策略:
options {
buildDiscarder(logRotator(numToKeepStr:'5'))
}
项目实践
使用 Docker 容器化构建环境
将敏感信息(如签名证书)存储在 Jenkins Credentials
通过 Blue Ocean 插件可视化流水线
结合 Prometheus + Grafana 监控构建指标
————————————————
原文链接:https://blog.csdn.net/zmk0110_/article/details/145959919
参考:https://cloud.tencent.com/developer/article/2194610
浙公网安备 33010602011771号