fix(jenkins): SNAPSHOT 模式自动递增 alpha 版本号(查询 registry 最新 alpha 后 +1)

这个提交包含在:
XuqmGroup 2026-06-16 13:18:43 +08:00
父节点 e5130c4627
当前提交 f727478e53

19
Jenkinsfile vendored
查看文件

@ -91,8 +91,23 @@ pipeline {
def newVer
if (params.SNAPSHOT) {
// SNAPSHOT仅追加 -alpha.1 后缀,不修改 package.json,不 commit
newVer = baseVer + '-alpha.1'
// SNAPSHOT查询 registry 上最新的 alpha 版本,自动递增
def alphaNum = 1
try {
def remoteVer = bat(
script: "@npm view ${pkg} dist-tags.alpha --registry %NEXUS_REGISTRY% 2>nul",
returnStdout: true
).trim()
if (remoteVer && remoteVer.matches(/.*-alpha\.\d+$/)) {
def matcher = (remoteVer =~ /-alpha\.(\d+)$/)
if (matcher.find()) {
alphaNum = matcher.group(1).toInteger() + 1
}
}
} catch (Exception e) {
echo "Could not query remote version for ${pkg}, using alpha.1"
}
newVer = baseVer + "-alpha.${alphaNum}"
echo "SNAPSHOT publish: ${pkg} → ${newVer} (tag: alpha)"
// 临时写入 package.json 供 npm publish 读取(不 commit
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');" """