2026-05-09 14:53:42 +08:00
|
|
|
|
pipeline {
|
|
|
|
|
|
agent any
|
|
|
|
|
|
|
|
|
|
|
|
environment {
|
|
|
|
|
|
NEXUS_REGISTRY = 'https://nexus.xuqinmin.com/repository/npm-hosted/'
|
2026-05-14 16:27:49 +08:00
|
|
|
|
GIT_URL = 'https://xuqinmin.com/xuqmGroup/XuqmGroup-RNSDK.git'
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
options {
|
|
|
|
|
|
timeout(time: 30, unit: 'MINUTES')
|
|
|
|
|
|
buildDiscarder(logRotator(numToKeepStr: '20'))
|
|
|
|
|
|
disableConcurrentBuilds()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-23 01:20:58 +08:00
|
|
|
|
parameters {
|
|
|
|
|
|
// ── 版本升级策略 ─────────────────────────────────────────────────────
|
2026-05-23 01:25:12 +08:00
|
|
|
|
choice(name: 'VERSION_BUMP', choices: ['patch', 'minor', 'major'],
|
2026-05-23 01:20:58 +08:00
|
|
|
|
description: '版本升级策略: major(1.0.0→2.0.0), minor(1.0.0→1.1.0), patch(1.0.0→1.0.1)')
|
|
|
|
|
|
booleanParam(name: 'CUSTOM_VERSION', defaultValue: false,
|
|
|
|
|
|
description: '勾选后使用下方自定义版本号(忽略VERSION_BUMP)')
|
|
|
|
|
|
|
|
|
|
|
|
// ── 模块自定义版本号(仅CUSTOM_VERSION=true时生效)───────────────────
|
|
|
|
|
|
string(name: 'COMMON_VERSION', defaultValue: '', description: '@xuqm/rn-common 自定义版本号(仅CUSTOM_VERSION=true时生效)')
|
|
|
|
|
|
string(name: 'IM_VERSION', defaultValue: '', description: '@xuqm/rn-im 自定义版本号')
|
|
|
|
|
|
string(name: 'PUSH_VERSION', defaultValue: '', description: '@xuqm/rn-push 自定义版本号')
|
|
|
|
|
|
string(name: 'UPDATE_VERSION', defaultValue: '', description: '@xuqm/rn-update 自定义版本号')
|
|
|
|
|
|
string(name: 'XWEBVIEW_VERSION',defaultValue: '', description: '@xuqm/rn-xwebview 自定义版本号')
|
|
|
|
|
|
string(name: 'LICENSE_VERSION', defaultValue: '', description: '@xuqm/rn-license 自定义版本号')
|
|
|
|
|
|
|
|
|
|
|
|
// ── 模块选择(每行一个)──────────────────────────────────────────
|
|
|
|
|
|
text(name: 'MODULES', defaultValue: 'common\nim\npush\nupdate\nxwebview\nlicense',
|
|
|
|
|
|
description: '要发布的模块,每行一个。可选: common im push update xwebview license')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-09 14:53:42 +08:00
|
|
|
|
stages {
|
2026-05-23 01:20:58 +08:00
|
|
|
|
|
|
|
|
|
|
// ── 1. 检出代码 ─────────────────────────────────────────────────────────
|
2026-05-09 14:53:42 +08:00
|
|
|
|
stage('Checkout') {
|
|
|
|
|
|
steps {
|
2026-05-16 11:49:32 +08:00
|
|
|
|
checkout([
|
2026-05-23 01:20:58 +08:00
|
|
|
|
$class: 'GitSCM',
|
|
|
|
|
|
branches: [[name: 'main']],
|
|
|
|
|
|
extensions: [[$class: 'CleanBeforeCheckout']],
|
|
|
|
|
|
userRemoteConfigs: scm.userRemoteConfigs
|
2026-05-16 11:49:32 +08:00
|
|
|
|
])
|
2026-05-09 14:53:42 +08:00
|
|
|
|
script {
|
2026-05-23 01:20:58 +08:00
|
|
|
|
env.GIT_COMMIT_SHORT = bat(
|
|
|
|
|
|
script: '@git rev-parse --short HEAD',
|
|
|
|
|
|
returnStdout: true
|
|
|
|
|
|
).trim()
|
|
|
|
|
|
|
|
|
|
|
|
// ── 解析选中的模块 ──────────────────────────────────────────
|
|
|
|
|
|
// 映射:参数名 → [目录, npm包名, 版本参数值]
|
|
|
|
|
|
def moduleMap = [
|
|
|
|
|
|
common: ['packages/common', '@xuqm/rn-common', params.COMMON_VERSION],
|
|
|
|
|
|
im: ['packages/im', '@xuqm/rn-im', params.IM_VERSION],
|
|
|
|
|
|
push: ['packages/push', '@xuqm/rn-push', params.PUSH_VERSION],
|
|
|
|
|
|
update: ['packages/update', '@xuqm/rn-update', params.UPDATE_VERSION],
|
|
|
|
|
|
xwebview: ['packages/xwebview', '@xuqm/rn-xwebview', params.XWEBVIEW_VERSION],
|
|
|
|
|
|
license: ['packages/license', '@xuqm/rn-license', params.LICENSE_VERSION],
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def requestedModules = params.MODULES
|
|
|
|
|
|
.split(/\r?\n/)
|
|
|
|
|
|
.collect { it.trim() }
|
|
|
|
|
|
.findAll { it && moduleMap.containsKey(it) }
|
|
|
|
|
|
|
|
|
|
|
|
if (requestedModules.isEmpty()) {
|
|
|
|
|
|
error "MODULES param is empty or contains no valid module names."
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 保存为逗号分隔的环境变量供后续阶段使用
|
|
|
|
|
|
env.SELECTED_MODULES = requestedModules.join(',')
|
|
|
|
|
|
|
|
|
|
|
|
// ── 解析版本号 ──────────────────────────────────────────
|
|
|
|
|
|
for (mod in requestedModules) {
|
|
|
|
|
|
def (dir, pkg, ver) = moduleMap[mod]
|
|
|
|
|
|
if (params.CUSTOM_VERSION && ver?.trim()) {
|
|
|
|
|
|
// 使用自定义版本号
|
|
|
|
|
|
echo "Overriding ${pkg} version → ${ver.trim()}"
|
|
|
|
|
|
bat """
|
|
|
|
|
|
node -e "var fs=require('fs'),p='${dir}/package.json',j=JSON.parse(fs.readFileSync(p,'utf8'));j.version='${ver.trim()}';fs.writeFileSync(p,JSON.stringify(j,null,2)+'\\n','utf8');console.log('Updated '+p+' to '+j.version)"
|
|
|
|
|
|
"""
|
|
|
|
|
|
} else if (!params.CUSTOM_VERSION) {
|
|
|
|
|
|
// 自动升级版本号
|
|
|
|
|
|
def currentVer = bat(
|
|
|
|
|
|
script: "@node -p \"require('./${dir}/package.json').version\"",
|
|
|
|
|
|
returnStdout: true
|
|
|
|
|
|
).trim()
|
|
|
|
|
|
def parts = currentVer.tokenize('.')
|
|
|
|
|
|
while (parts.size() < 3) { parts.add('0') }
|
|
|
|
|
|
switch (params.VERSION_BUMP) {
|
|
|
|
|
|
case 'major':
|
|
|
|
|
|
parts[0] = (parts[0].toInteger() + 1).toString()
|
|
|
|
|
|
parts[1] = '0'
|
|
|
|
|
|
parts[2] = '0'
|
|
|
|
|
|
break
|
|
|
|
|
|
case 'minor':
|
|
|
|
|
|
parts[1] = (parts[1].toInteger() + 1).toString()
|
|
|
|
|
|
parts[2] = '0'
|
|
|
|
|
|
break
|
|
|
|
|
|
case 'patch':
|
|
|
|
|
|
default:
|
|
|
|
|
|
parts[2] = (parts[2].toInteger() + 1).toString()
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
def newVer = parts.join('.')
|
|
|
|
|
|
echo "Auto-bumping ${pkg}: ${currentVer} → ${newVer}"
|
|
|
|
|
|
bat """
|
|
|
|
|
|
node -e "var fs=require('fs'),p='${dir}/package.json',j=JSON.parse(fs.readFileSync(p,'utf8'));j.version='${newVer}';fs.writeFileSync(p,JSON.stringify(j,null,2)+'\\n','utf8');console.log('Updated '+p+' to '+j.version)"
|
|
|
|
|
|
"""
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-23 01:20:58 +08:00
|
|
|
|
// ── 2. 发布信息 ─────────────────────────────────────────────────────────
|
|
|
|
|
|
stage('Publish Info') {
|
2026-05-09 14:53:42 +08:00
|
|
|
|
steps {
|
2026-05-23 01:20:58 +08:00
|
|
|
|
script {
|
|
|
|
|
|
def selected = env.SELECTED_MODULES.split(',')
|
|
|
|
|
|
def dirMap = [
|
|
|
|
|
|
common: 'packages/common',
|
|
|
|
|
|
im: 'packages/im',
|
|
|
|
|
|
push: 'packages/push',
|
|
|
|
|
|
update: 'packages/update',
|
|
|
|
|
|
xwebview: 'packages/xwebview',
|
|
|
|
|
|
license: 'packages/license',
|
|
|
|
|
|
]
|
|
|
|
|
|
echo "Git Commit : ${env.GIT_COMMIT_SHORT}"
|
|
|
|
|
|
echo "Modules to publish (${selected.size()}):"
|
|
|
|
|
|
for (mod in selected) {
|
|
|
|
|
|
def dir = dirMap[mod]
|
|
|
|
|
|
def ver = bat(
|
|
|
|
|
|
script: "@node -p \"require('./${dir}/package.json').version\"",
|
|
|
|
|
|
returnStdout: true
|
|
|
|
|
|
).trim()
|
|
|
|
|
|
echo " ${mod.padRight(10)} (${dir}) → v${ver}"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-23 01:20:58 +08:00
|
|
|
|
// ── 3. 安装依赖 ─────────────────────────────────────────────────────────
|
2026-05-09 14:53:42 +08:00
|
|
|
|
stage('Install Dependencies') {
|
|
|
|
|
|
steps {
|
2026-05-23 01:20:58 +08:00
|
|
|
|
withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS',
|
|
|
|
|
|
passwordVariable: 'NPM_PASS',
|
|
|
|
|
|
usernameVariable: 'NPM_USER')]) {
|
2026-05-16 12:25:32 +08:00
|
|
|
|
bat """
|
2026-05-16 12:41:43 +08:00
|
|
|
|
powershell -NonInteractive -Command "\$auth=[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(\$env:NPM_USER+':'+\$env:NPM_PASS)); Set-Content .npmrc ('@xuqm:registry=https://nexus.xuqinmin.com/repository/npm-hosted/' + [char]10 + '//nexus.xuqinmin.com/repository/npm-hosted/:_auth=' + \$auth) -Encoding ASCII"
|
2026-05-16 12:25:32 +08:00
|
|
|
|
npm install --legacy-peer-deps
|
|
|
|
|
|
"""
|
2026-05-16 11:49:32 +08:00
|
|
|
|
}
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-23 01:20:58 +08:00
|
|
|
|
// ── 4. 类型检查 ─────────────────────────────────────────────────────────
|
2026-05-09 14:53:42 +08:00
|
|
|
|
stage('Type Check') {
|
|
|
|
|
|
steps {
|
2026-05-23 01:20:58 +08:00
|
|
|
|
script {
|
|
|
|
|
|
// 在每个选中的包目录运行类型检查(允许失败)
|
|
|
|
|
|
def selected = env.SELECTED_MODULES.split(',')
|
|
|
|
|
|
def dirMap = [
|
|
|
|
|
|
common: 'packages/common',
|
|
|
|
|
|
im: 'packages/im',
|
|
|
|
|
|
push: 'packages/push',
|
|
|
|
|
|
update: 'packages/update',
|
|
|
|
|
|
xwebview: 'packages/xwebview',
|
|
|
|
|
|
license: 'packages/license',
|
|
|
|
|
|
]
|
|
|
|
|
|
for (mod in selected) {
|
|
|
|
|
|
def dir = dirMap[mod]
|
|
|
|
|
|
echo "Type-checking ${mod} (${dir})"
|
|
|
|
|
|
bat "cd ${dir} && npm run typecheck || ver>nul"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-23 01:20:58 +08:00
|
|
|
|
// ── 5. 测试 ────────────────────────────────────────────────────────────
|
2026-05-09 14:53:42 +08:00
|
|
|
|
stage('Tests') {
|
|
|
|
|
|
steps {
|
2026-05-14 16:27:49 +08:00
|
|
|
|
bat 'npm test > test-results.txt 2>&1 || ver>nul'
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
post {
|
|
|
|
|
|
always {
|
|
|
|
|
|
archiveArtifacts artifacts: 'test-results.txt', allowEmptyArchive: true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-23 01:20:58 +08:00
|
|
|
|
// ── 6. 发布到 Nexus ─────────────────────────────────────────────────────
|
2026-05-09 14:53:42 +08:00
|
|
|
|
stage('Publish to Nexus') {
|
|
|
|
|
|
steps {
|
2026-05-23 01:20:58 +08:00
|
|
|
|
withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS',
|
|
|
|
|
|
passwordVariable: 'NPM_PASS',
|
|
|
|
|
|
usernameVariable: 'NPM_USER')]) {
|
|
|
|
|
|
script {
|
|
|
|
|
|
// 写入带认证信息的 .npmrc
|
|
|
|
|
|
bat """
|
|
|
|
|
|
powershell -NonInteractive -Command "\$auth=[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(\$env:NPM_USER+':'+\$env:NPM_PASS)); Set-Content .npmrc ('@xuqm:registry=https://nexus.xuqinmin.com/repository/npm-hosted/' + [char]10 + '//nexus.xuqinmin.com/repository/npm-hosted/:_auth=' + \$auth) -Encoding ASCII"
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def selected = env.SELECTED_MODULES.split(',')
|
|
|
|
|
|
def dirMap = [
|
|
|
|
|
|
common: 'packages/common',
|
|
|
|
|
|
im: 'packages/im',
|
|
|
|
|
|
push: 'packages/push',
|
|
|
|
|
|
update: 'packages/update',
|
|
|
|
|
|
xwebview: 'packages/xwebview',
|
|
|
|
|
|
license: 'packages/license',
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
for (mod in selected) {
|
|
|
|
|
|
def dir = dirMap[mod]
|
|
|
|
|
|
echo "Publishing ${mod} from ${dir}"
|
|
|
|
|
|
// 复制 .npmrc 到包目录,发布,然后清理
|
|
|
|
|
|
bat """
|
|
|
|
|
|
copy .npmrc ${dir}\\.npmrc
|
|
|
|
|
|
cd ${dir} && npm publish --registry %NEXUS_REGISTRY%
|
|
|
|
|
|
del ${dir}\\.npmrc 2>nul || exit 0
|
|
|
|
|
|
"""
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-16 11:49:32 +08:00
|
|
|
|
}
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
2026-05-16 11:53:11 +08:00
|
|
|
|
post {
|
|
|
|
|
|
always {
|
|
|
|
|
|
bat 'del .npmrc 2>nul || exit 0'
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
post {
|
|
|
|
|
|
success {
|
2026-05-23 01:20:58 +08:00
|
|
|
|
script {
|
|
|
|
|
|
def selected = env.SELECTED_MODULES?.split(',') ?: []
|
|
|
|
|
|
echo "RN SDK 构建成功 — 已发布模块: ${selected.join(', ')} (Commit: ${env.GIT_COMMIT_SHORT})"
|
|
|
|
|
|
}
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
failure {
|
2026-05-14 18:50:28 +08:00
|
|
|
|
echo "RN SDK 构建失败,请检查日志"
|
2026-05-09 14:53:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|