150 lines
5.7 KiB
Groovy
150 lines
5.7 KiB
Groovy
//=================================================================
|
||
// Byway Studios Inc. Confidential Information.
|
||
// Copyright Byway Studios Inc. All rights reserved
|
||
//=================================================================
|
||
|
||
def call(Map config)
|
||
{
|
||
pipeline
|
||
{
|
||
agent
|
||
{
|
||
label config.winbakeLabel
|
||
}
|
||
parameters
|
||
{
|
||
booleanParam(name: 'BuildNonTuyoo', defaultValue: true, description: 'Should We Build APK without Tuyoo SDK Login')
|
||
}
|
||
options
|
||
{
|
||
skipDefaultCheckout(true) // ★ 关键:禁止 Jenkins 自动 checkout library
|
||
}
|
||
stages
|
||
{
|
||
stage("Checkout Unity Project")
|
||
{
|
||
options
|
||
{
|
||
timeout(30)
|
||
}
|
||
steps
|
||
{
|
||
script {
|
||
// 配置 Git 支持长路径(解决 Windows 260 字符限制)
|
||
bat 'git config --global core.longpaths true'
|
||
}
|
||
script {
|
||
// 最小化处理:checkout 前仅重置子模块,避免残留改动导致冲突
|
||
bat '''
|
||
if exist .gitmodules (
|
||
git submodule foreach --recursive git reset --hard
|
||
)
|
||
'''
|
||
}
|
||
checkout([
|
||
$class: 'GitSCM',
|
||
branches: [[name: '*/QA']], // 分支名
|
||
userRemoteConfigs: [[
|
||
url: 'git@gitea.bywaystudios.com:pet_home/AplusB_Pet_nation.git',
|
||
credentialsId: '503eaa43-0676-40ac-81c0-d9c5cc8b4ff7'
|
||
]],
|
||
extensions: [
|
||
[$class: 'CleanCheckout'],
|
||
[$class: 'SubmoduleOption',
|
||
disableSubmodules: false,
|
||
parentCredentials: true,
|
||
recursiveSubmodules: true,
|
||
trackingSubmodules: false,
|
||
reference: '',
|
||
timeout: 20]
|
||
]
|
||
])
|
||
}
|
||
}
|
||
stage("Build Unity Android")
|
||
{
|
||
options
|
||
{
|
||
timeout(100)
|
||
}
|
||
steps
|
||
{
|
||
BuildAndroid(config)
|
||
}
|
||
}
|
||
stage("AchiveArtifact")
|
||
{
|
||
options
|
||
{
|
||
timeout(20)
|
||
}
|
||
steps
|
||
{
|
||
archiveArtifact("Android_stable")
|
||
}
|
||
}
|
||
}
|
||
post
|
||
{
|
||
always
|
||
{
|
||
script {
|
||
// 获取触发者
|
||
def triggerUser = "自动触发"
|
||
def buildCause = currentBuild.getBuildCauses()
|
||
if (buildCause && buildCause.size() > 0 && buildCause[0].userName) {
|
||
triggerUser = buildCause[0].userName
|
||
}
|
||
|
||
// 获取失败阶段(仅失败时)
|
||
def failedStage = ""
|
||
if (currentBuild.currentResult == 'FAILURE') {
|
||
def stages = currentBuild.rawBuild.getAction(org.jenkinsci.plugins.workflow.job.views.FlowGraphAction)?.getNodes()
|
||
if (stages) {
|
||
for (stage in stages) {
|
||
if (stage.getError() != null) {
|
||
failedStage = "\n- 失败阶段: ${stage.getDisplayName()}"
|
||
break
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 收集提交记录
|
||
def changeString = ""
|
||
def changeLogSets = currentBuild.changeSets
|
||
if (changeLogSets.size() > 0) {
|
||
changeString = "\n\n提交记录:\n"
|
||
for (int i = 0; i < changeLogSets.size(); i++) {
|
||
def entries = changeLogSets[i].items
|
||
for (int j = 0; j < entries.length; j++) {
|
||
def entry = entries[j]
|
||
changeString += "- ${entry.commitId.take(7)} ${entry.msg} - ${entry.author}\n"
|
||
}
|
||
}
|
||
} else {
|
||
changeString = "\n\n提交记录: 无变更"
|
||
}
|
||
|
||
dingtalk(
|
||
robot:'dingtalk_unity_1',
|
||
type:'MARKDOWN',
|
||
title:"${currentBuild.currentResult} - stable #${env.BUILD_NUMBER}",
|
||
text: [
|
||
"### ${currentBuild.currentResult}",
|
||
"\n构建信息:",
|
||
"- 项目: ${env.JOB_NAME}",
|
||
"- 构建号: #${env.BUILD_NUMBER}",
|
||
"- 分支: QA",
|
||
"- 触发者: ${triggerUser}",
|
||
"- 耗时: ${currentBuild.durationString}${failedStage}",
|
||
"\n链接:",
|
||
"- [下载链接](${env.BUILD_URL})",
|
||
changeString
|
||
]
|
||
)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
} |