167 lines
7.4 KiB
Plaintext
167 lines
7.4 KiB
Plaintext
pipeline {
|
||
agent {
|
||
label 'windows && win2022'
|
||
}
|
||
|
||
options {
|
||
disableConcurrentBuilds()
|
||
skipDefaultCheckout(true)
|
||
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20'))
|
||
}
|
||
|
||
environment {
|
||
GIT_REMOTE_URL = 'ssh://git@192.168.35.82:2222/GenarrativeAI/Genarrative.git'
|
||
GIT_REMOTE_CREDENTIAL_ID = 'genarrative-local-gitea-ssh'
|
||
GENARRATIVE_NPM_VERSION = '10.9.7'
|
||
AGC_OSS_BUCKET = 'agc-dev'
|
||
AGC_OSS_ENDPOINT = 'oss-rg-china-mainland.aliyuncs.com'
|
||
AGC_WINDOWS_PATH = 'C:\\Tools\\Git\\cmd;C:\\Program Files\\nodejs;C:\\Users\\Administrator\\.cargo\\bin;C:\\Tools\\ossutil;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\'
|
||
}
|
||
|
||
parameters {
|
||
string(name: 'SOURCE_BRANCH', defaultValue: 'master', description: '源码分支')
|
||
string(name: 'COMMIT_HASH', defaultValue: '', description: '可选,指定属于 SOURCE_BRANCH 的 Git commit')
|
||
string(name: 'AGC_RELEASE_VERSION', defaultValue: '', description: '可选,指定三段版本号;留空则按 OSS 与本地版本自动递增 patch')
|
||
text(name: 'AGC_UPDATE_RELEASE_NOTES', defaultValue: '', description: '可选,支持多行文本,写入 latest.json 的发布说明')
|
||
string(name: 'OSSUTIL_BIN', defaultValue: 'ossutil', description: 'ossutil 或 ossutil.exe 的绝对路径/命令名')
|
||
}
|
||
|
||
stages {
|
||
stage('Checkout') {
|
||
steps {
|
||
withCredentials([sshUserPrivateKey(credentialsId: env.GIT_REMOTE_CREDENTIAL_ID, keyFileVariable: 'GIT_SSH_KEY', usernameVariable: 'GIT_SSH_USER')]) {
|
||
powershell '''
|
||
$ErrorActionPreference = 'Stop'
|
||
$env:GIT_SSH_COMMAND = "ssh -i `"$env:GIT_SSH_KEY`" -o StrictHostKeyChecking=no"
|
||
$git = 'C:\\Tools\\Git\\cmd\\git.exe'
|
||
if (-not (Test-Path $git)) { throw "找不到 Git: $git" }
|
||
if (Test-Path '.git') {
|
||
& $git fetch --tags --force --prune origin "+refs/heads/$($env:SOURCE_BRANCH):refs/remotes/origin/$($env:SOURCE_BRANCH)"
|
||
if ($LASTEXITCODE -ne 0) { throw 'Git fetch 失败' }
|
||
& $git clean -fdx
|
||
& $git reset --hard "origin/$($env:SOURCE_BRANCH)"
|
||
} else {
|
||
& $git clone --no-single-branch $env:GIT_REMOTE_URL .
|
||
if ($LASTEXITCODE -ne 0) { throw 'Git clone 失败' }
|
||
& $git fetch --tags --force origin "refs/heads/$($env:SOURCE_BRANCH):refs/remotes/origin/$($env:SOURCE_BRANCH)"
|
||
if ($LASTEXITCODE -ne 0) { throw 'Git fetch 分支失败' }
|
||
& $git checkout --detach "origin/$($env:SOURCE_BRANCH)"
|
||
}
|
||
$commit = ([string]$env:COMMIT_HASH).Trim()
|
||
if ($commit) {
|
||
if ($commit -notmatch '^[0-9a-fA-F]{7,64}$') {
|
||
throw 'COMMIT_HASH 必须是 7-64 位十六进制 Git commit。'
|
||
}
|
||
& $git cat-file -e "${commit}^{commit}"
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "COMMIT_HASH 不存在: $commit"
|
||
}
|
||
$branchRef = "refs/remotes/origin/$($env:SOURCE_BRANCH)"
|
||
& $git merge-base --is-ancestor $commit $branchRef
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "COMMIT_HASH 不属于 SOURCE_BRANCH: $($env:SOURCE_BRANCH)"
|
||
}
|
||
& $git checkout --detach $commit
|
||
}
|
||
$resolved = (& $git rev-parse HEAD).Trim()
|
||
Set-Content -Path '.jenkins-source-commit' -Value $resolved -NoNewline
|
||
Write-Host "源码 commit=$resolved"
|
||
'''
|
||
}
|
||
}
|
||
}
|
||
|
||
stage('Toolchain preflight') {
|
||
steps {
|
||
withEnv(["PATH=${env.AGC_WINDOWS_PATH}", "OSSUTIL_BIN=${params.OSSUTIL_BIN}"]) {
|
||
powershell '''
|
||
$ErrorActionPreference = 'Stop'
|
||
$actualNpm = (npm --version).Trim()
|
||
if ($actualNpm -ne $env:GENARRATIVE_NPM_VERSION) {
|
||
throw "npm 版本不匹配:期望 $($env:GENARRATIVE_NPM_VERSION),实际 $actualNpm"
|
||
}
|
||
foreach ($commandName in @('node', 'npm', 'rustc', 'cargo')) {
|
||
if (-not (Get-Command $commandName -ErrorAction SilentlyContinue)) {
|
||
throw "Windows AGC 节点缺少 $commandName,请先安装并加入 Jenkins Agent PATH。"
|
||
}
|
||
}
|
||
$ossutil = ([string]$env:OSSUTIL_BIN).Trim()
|
||
if (-not $ossutil) { $ossutil = 'ossutil' }
|
||
if (-not (Get-Command $ossutil -ErrorAction SilentlyContinue)) {
|
||
throw "Windows AGC 节点缺少 ossutil:$ossutil"
|
||
}
|
||
Write-Host "node=$((node --version).Trim())"
|
||
Write-Host "npm=$actualNpm"
|
||
Write-Host "rustc=$((rustc --version).Trim())"
|
||
Write-Host "cargo=$((cargo --version).Trim())"
|
||
Write-Host "jenkins-user=$([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)"
|
||
Write-Host "local-app-data=$env:LOCALAPPDATA"
|
||
$targetTools = Join-Path $PWD 'apps/ai-game-creator-shell/src-tauri/target/.tauri'
|
||
New-Item -ItemType Directory -Force -Path $targetTools | Out-Null
|
||
$probe = Join-Path $targetTools '.jenkins-write-probe'
|
||
Set-Content -Path $probe -Value 'ok' -NoNewline
|
||
Remove-Item -LiteralPath $probe -Force
|
||
Write-Host "tauri-tools-dir=$targetTools"
|
||
'''
|
||
}
|
||
}
|
||
}
|
||
|
||
stage('Install dependencies') {
|
||
steps {
|
||
withEnv(["PATH=${env.AGC_WINDOWS_PATH}"]) {
|
||
powershell '''
|
||
$ErrorActionPreference = 'Stop'
|
||
npm ci --no-audit --no-fund
|
||
'''
|
||
}
|
||
}
|
||
}
|
||
|
||
stage('Build and upload') {
|
||
steps {
|
||
withCredentials([
|
||
string(credentialsId: 'AliyunAccessKeyId', variable: 'AGC_OSS_ACCESS_KEY_ID'),
|
||
string(credentialsId: 'AliyunaccessKeySecret', variable: 'AGC_OSS_ACCESS_KEY_SECRET'),
|
||
]) {
|
||
withEnv([
|
||
"PATH=${env.AGC_WINDOWS_PATH}",
|
||
"OSSUTIL_BIN=${params.OSSUTIL_BIN}",
|
||
"AGC_RELEASE_VERSION=${params.AGC_RELEASE_VERSION}",
|
||
"AGC_UPDATE_RELEASE_NOTES=${params.AGC_UPDATE_RELEASE_NOTES}",
|
||
]) {
|
||
powershell '''
|
||
$ErrorActionPreference = 'Stop'
|
||
npm run ai-game-creator-shell:release:upload
|
||
$buildExitCode = $LASTEXITCODE
|
||
if ($buildExitCode -ne 0) {
|
||
$nsis = Join-Path $PWD 'apps/ai-game-creator-shell/src-tauri/target/.tauri/NSIS/makensis.exe'
|
||
Write-Host "Tauri NSIS path=$nsis"
|
||
if (Test-Path $nsis) {
|
||
Get-Item $nsis | Select-Object FullName, Length, LastWriteTime
|
||
try { & $nsis -VERSION } catch { Write-Host "无法直接启动 Tauri NSIS:$($_.Exception.Message)" }
|
||
} else {
|
||
Write-Host 'Tauri NSIS makensis.exe 不存在。'
|
||
}
|
||
throw "AGC 发布构建失败,退出码=$buildExitCode"
|
||
}
|
||
'''
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
stage('Archive release') {
|
||
steps {
|
||
archiveArtifacts artifacts: 'apps/ai-game-creator-shell/src-tauri/target/x86_64-pc-windows-msvc/release/bundle/**/*.exe,apps/ai-game-creator-shell/src-tauri/target/x86_64-pc-windows-msvc/release/bundle/latest.json,.jenkins-source-commit', fingerprint: true
|
||
}
|
||
}
|
||
}
|
||
|
||
post {
|
||
success {
|
||
echo 'AGC Windows x64 安装包已构建并上传 OSS。'
|
||
}
|
||
}
|
||
}
|