XuqmGroup-H5SDK/Jenkinsfile
徐勤民 6a356f246a ci: fix Jenkinsfile and add @xuqm-private/h5-sdk publish step
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 21:13:05 +08:00

116 行
3.8 KiB
Groovy

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

pipeline {
agent any
parameters {
string(name: 'VERSION', defaultValue: '', description: '发布版本号(留空使用 package.json 中的 version')
booleanParam(name: 'PUBLISH', defaultValue: true, description: '是否发布到 Nexus npm 仓库')
}
environment {
NEXUS_REGISTRY = 'https://nexus.xuqinmin.com/repository/npm-hosted/'
GIT_URL = 'https://xuqinmin.com/xuqmGroup/XuqmGroup-H5SDK.git'
}
options {
timeout(time: 20, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr: '20'))
disableConcurrentBuilds()
}
stages {
stage('Checkout') {
steps {
checkout([
$class: 'GitSCM',
branches: [[name: 'main']],
extensions: [[$class: 'CleanBeforeCheckout']],
userRemoteConfigs: scm.userRemoteConfigs
])
script {
env.GIT_COMMIT_SHORT = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
if (params.VERSION?.trim()) {
sh "npm version ${params.VERSION} --no-git-tag-version"
}
env.PUBLISH_VERSION = sh(script: 'node -p "require(\'./package.json\').version"', returnStdout: true).trim()
}
}
}
stage('Build Info') {
steps {
echo "发布版本: ${env.PUBLISH_VERSION}"
echo "Git Commit: ${env.GIT_COMMIT_SHORT}"
}
}
stage('Install Dependencies') {
steps {
sh 'npm ci'
}
}
stage('Type Check') {
steps {
sh 'npm run type-check'
}
}
stage('Build') {
steps {
sh 'npm run build'
}
}
stage('Publish to Nexus') {
when {
expression { return params.PUBLISH }
}
steps {
withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) {
sh """
echo "//nexus.xuqinmin.com/repository/npm-hosted/:_auth=\$(echo -n '\${NPM_USER}:\${NPM_PASS}' | base64)" > .npmrc
npm publish --registry ${NEXUS_REGISTRY}
"""
}
}
post {
always {
sh 'rm -f .npmrc 2>/dev/null || true'
}
}
}
stage('Publish Private SDK to Nexus') {
when {
expression { return params.PUBLISH }
}
steps {
withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) {
sh """
echo "//nexus.xuqinmin.com/repository/npm-hosted/:_auth=\$(echo -n '\${NPM_USER}:\${NPM_PASS}' | base64)" > .npmrc
cp package.json package.json.bak
cp package.private.json package.json
npm publish --registry ${NEXUS_REGISTRY}
mv package.json.bak package.json
"""
}
}
post {
always {
sh 'rm -f .npmrc 2>/dev/null || true'
sh 'if [ -f package.json.bak ]; then mv package.json.bak package.json; fi'
}
}
}
}
post {
success {
echo "H5 SDK v${env.PUBLISH_VERSION} 构建成功 (Commit: ${env.GIT_COMMIT_SHORT})"
}
failure {
echo "H5 SDK 构建失败,请检查日志"
}
}
}