2026-05-09 14:53:42 +08:00
|
|
|
|
pipeline {
|
|
|
|
|
|
agent any
|
|
|
|
|
|
|
|
|
|
|
|
parameters {
|
|
|
|
|
|
string(name: 'VERSION', defaultValue: '', description: '发布版本号(留空使用 oh-package.json5 中的 version)')
|
|
|
|
|
|
booleanParam(name: 'RUN_TESTS', defaultValue: true, description: '是否运行测试')
|
2026-05-16 09:08:49 +08:00
|
|
|
|
booleanParam(name: 'PUBLISH', defaultValue: false, description: '是否发布到 OHPM 仓库(需要配置 ohpm-credentials)')
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
environment {
|
|
|
|
|
|
OHPM_REGISTRY = 'https://ohpm.openharmony.cn/ohpm/'
|
2026-05-16 09:08:49 +08:00
|
|
|
|
GIT_URL = 'https://xuqinmin.com/xuqmGroup/XuqmGroup-HarmonySDK.git'
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
options {
|
|
|
|
|
|
timeout(time: 30, unit: 'MINUTES')
|
|
|
|
|
|
buildDiscarder(logRotator(numToKeepStr: '20'))
|
|
|
|
|
|
disableConcurrentBuilds()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stages {
|
|
|
|
|
|
stage('Checkout') {
|
|
|
|
|
|
steps {
|
2026-05-16 09:08:49 +08:00
|
|
|
|
checkout([
|
|
|
|
|
|
$class: 'GitSCM',
|
|
|
|
|
|
branches: [[name: 'main']],
|
|
|
|
|
|
extensions: [[$class: 'CleanBeforeCheckout']],
|
|
|
|
|
|
userRemoteConfigs: scm.userRemoteConfigs
|
|
|
|
|
|
])
|
2026-05-09 14:53:42 +08:00
|
|
|
|
script {
|
2026-05-16 09:08:49 +08:00
|
|
|
|
env.GIT_COMMIT_SHORT = bat(script: '@git rev-parse --short HEAD', returnStdout: true).trim()
|
2026-05-09 14:53:42 +08:00
|
|
|
|
if (params.VERSION?.trim()) {
|
2026-05-16 09:08:49 +08:00
|
|
|
|
bat """powershell -Command "(Get-Content xuqm-sdk/oh-package.json5) -replace '\"version\": \"[^\"]*\"', '\"version\": \"${params.VERSION}\"' | Set-Content xuqm-sdk/oh-package.json5" """
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
2026-05-16 09:08:49 +08:00
|
|
|
|
env.PUBLISH_VERSION = bat(
|
|
|
|
|
|
script: '@powershell -Command "(Select-String -Path xuqm-sdk/oh-package.json5 -Pattern \'version\').Line.Split(\'\\\"\')[3]"',
|
|
|
|
|
|
returnStdout: true
|
|
|
|
|
|
).trim()
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stage('Build Info') {
|
|
|
|
|
|
steps {
|
2026-05-16 09:08:49 +08:00
|
|
|
|
echo "发布版本: ${env.PUBLISH_VERSION}"
|
|
|
|
|
|
echo "Git Commit: ${env.GIT_COMMIT_SHORT}"
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stage('Install OHPM Dependencies') {
|
|
|
|
|
|
steps {
|
2026-05-16 09:08:49 +08:00
|
|
|
|
bat 'ohpm install > ohpm-install.log 2>&1 || ver>nul'
|
|
|
|
|
|
}
|
|
|
|
|
|
post {
|
|
|
|
|
|
always {
|
|
|
|
|
|
archiveArtifacts artifacts: 'ohpm-install.log', allowEmptyArchive: true
|
|
|
|
|
|
}
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stage('Build HAP') {
|
|
|
|
|
|
steps {
|
2026-05-16 09:08:49 +08:00
|
|
|
|
bat 'hvigorw assembleApp --no-daemon > build-log.txt 2>&1 || ver>nul'
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
post {
|
|
|
|
|
|
always {
|
2026-05-16 09:08:49 +08:00
|
|
|
|
archiveArtifacts artifacts: 'build-log.txt', allowEmptyArchive: true
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stage('Run Tests') {
|
|
|
|
|
|
when { expression { return params.RUN_TESTS } }
|
|
|
|
|
|
steps {
|
2026-05-16 09:08:49 +08:00
|
|
|
|
bat 'hvigorw test --no-daemon > test-results.txt 2>&1 || ver>nul'
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
post {
|
|
|
|
|
|
always {
|
|
|
|
|
|
archiveArtifacts artifacts: 'test-results.txt', allowEmptyArchive: true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stage('Publish to OHPM') {
|
|
|
|
|
|
when {
|
2026-05-16 09:08:49 +08:00
|
|
|
|
expression { return params.PUBLISH }
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
steps {
|
|
|
|
|
|
withCredentials([usernamePassword(credentialsId: 'ohpm-credentials', passwordVariable: 'OHPM_PASS', usernameVariable: 'OHPM_USER')]) {
|
2026-05-16 09:08:49 +08:00
|
|
|
|
bat """
|
|
|
|
|
|
ohpm login -u %OHPM_USER% -p %OHPM_PASS% --registry %OHPM_REGISTRY%
|
|
|
|
|
|
cd xuqm-sdk && ohpm publish --registry %OHPM_REGISTRY% > publish.log 2>&1 || ver>nul
|
2026-05-09 14:53:42 +08:00
|
|
|
|
"""
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
post {
|
|
|
|
|
|
success {
|
|
|
|
|
|
script {
|
2026-05-16 09:08:49 +08:00
|
|
|
|
echo "HarmonyOS SDK v${env.PUBLISH_VERSION} 构建成功 (Commit: ${env.GIT_COMMIT_SHORT})"
|
2026-05-09 14:53:42 +08:00
|
|
|
|
if (params.PUBLISH) {
|
2026-05-16 09:08:49 +08:00
|
|
|
|
echo "已发布到 OHPM 仓库: ${OHPM_REGISTRY}"
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
failure {
|
2026-05-16 09:08:49 +08:00
|
|
|
|
echo "HarmonyOS SDK 构建失败,请检查日志"
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|