ci: fix Jenkinsfile for Windows Jenkins — bat, NEXUS_CREDS, XuqmGroup URL
这个提交包含在:
父节点
66801ca26c
当前提交
a6a5a1e8bf
59
Jenkinsfile
vendored
59
Jenkinsfile
vendored
@ -2,7 +2,6 @@ pipeline {
|
|||||||
agent any
|
agent any
|
||||||
|
|
||||||
parameters {
|
parameters {
|
||||||
string(name: 'BRANCH', defaultValue: 'main', description: 'Git 分支名')
|
|
||||||
string(name: 'VERSION', defaultValue: '', description: '发布版本号(留空使用 package.json 中的 version)')
|
string(name: 'VERSION', defaultValue: '', description: '发布版本号(留空使用 package.json 中的 version)')
|
||||||
booleanParam(name: 'RUN_TESTS', defaultValue: true, description: '是否运行测试')
|
booleanParam(name: 'RUN_TESTS', defaultValue: true, description: '是否运行测试')
|
||||||
booleanParam(name: 'PUBLISH', defaultValue: true, description: '是否发布到 Nexus npm 仓库')
|
booleanParam(name: 'PUBLISH', defaultValue: true, description: '是否发布到 Nexus npm 仓库')
|
||||||
@ -10,7 +9,7 @@ pipeline {
|
|||||||
|
|
||||||
environment {
|
environment {
|
||||||
NEXUS_REGISTRY = 'https://nexus.xuqinmin.com/repository/npm-hosted/'
|
NEXUS_REGISTRY = 'https://nexus.xuqinmin.com/repository/npm-hosted/'
|
||||||
GIT_URL = 'https://xuqinmin.com/xuqinmin12/XuqmGroup-Vue3SDK.git'
|
GIT_URL = 'https://xuqinmin.com/xuqmGroup/XuqmGroup-Vue3SDK.git'
|
||||||
NODE_VERSION = '22'
|
NODE_VERSION = '22'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,49 +22,51 @@ pipeline {
|
|||||||
stages {
|
stages {
|
||||||
stage('Checkout') {
|
stage('Checkout') {
|
||||||
steps {
|
steps {
|
||||||
checkout scm
|
checkout([
|
||||||
|
$class: 'GitSCM',
|
||||||
|
branches: [[name: 'main']],
|
||||||
|
extensions: [[$class: 'CleanBeforeCheckout']],
|
||||||
|
userRemoteConfigs: scm.userRemoteConfigs
|
||||||
|
])
|
||||||
script {
|
script {
|
||||||
env.GIT_COMMIT_SHORT = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
env.GIT_COMMIT_SHORT = bat(script: '@git rev-parse --short HEAD', returnStdout: true).trim()
|
||||||
if (params.VERSION?.trim()) {
|
if (params.VERSION?.trim()) {
|
||||||
sh "npm version ${params.VERSION} --no-git-tag-version"
|
bat "npm version ${params.VERSION} --no-git-tag-version"
|
||||||
}
|
}
|
||||||
env.PUBLISH_VERSION = sh(script: 'node -p "require(\"./package.json\").version"', returnStdout: true).trim()
|
env.PUBLISH_VERSION = bat(script: '@node -p "require(\'./package.json\').version"', returnStdout: true).trim()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build Info') {
|
stage('Build Info') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
echo "发布版本: ${env.PUBLISH_VERSION}"
|
||||||
echo "🚀 构建分支: ${params.BRANCH}"
|
echo "Git Commit: ${env.GIT_COMMIT_SHORT}"
|
||||||
echo "🏷️ 发布版本: ${env.PUBLISH_VERSION}"
|
|
||||||
echo "🔨 Git Commit: ${env.GIT_COMMIT_SHORT}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Install Dependencies') {
|
stage('Install Dependencies') {
|
||||||
steps {
|
steps {
|
||||||
sh 'npm ci'
|
bat 'npm ci'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Type Check') {
|
stage('Type Check') {
|
||||||
steps {
|
steps {
|
||||||
sh 'npm run type-check'
|
bat 'npm run type-check'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
steps {
|
steps {
|
||||||
sh 'npm run build'
|
bat 'npm run build'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Tests') {
|
stage('Tests') {
|
||||||
when { expression { return params.RUN_TESTS } }
|
when { expression { return params.RUN_TESTS } }
|
||||||
steps {
|
steps {
|
||||||
sh 'npm run test 2>&1 | tee test-results.txt'
|
bat 'npm run test > test-results.txt 2>&1 || ver>nul'
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
@ -76,17 +77,20 @@ pipeline {
|
|||||||
|
|
||||||
stage('Publish to Nexus') {
|
stage('Publish to Nexus') {
|
||||||
when {
|
when {
|
||||||
allOf {
|
|
||||||
branch 'main'
|
|
||||||
expression { return params.PUBLISH }
|
expression { return params.PUBLISH }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
withCredentials([usernamePassword(credentialsId: 'nexus-npm-credentials', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) {
|
withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) {
|
||||||
sh """
|
script {
|
||||||
echo "//nexus.xuqinmin.com/repository/npm-hosted/:_auth=\$(echo -n '\${NPM_USER}:\${NPM_PASS}' | base64)" > .npmrc
|
def auth = "${NPM_USER}:${NPM_PASS}".bytes.encodeBase64().toString()
|
||||||
npm publish --registry ${NEXUS_REGISTRY}
|
writeFile file: '.npmrc', text: "//nexus.xuqinmin.com/repository/npm-hosted/:_auth=${auth}\n"
|
||||||
"""
|
bat "npm publish --registry %NEXUS_REGISTRY%"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
bat 'del .npmrc 2>nul || exit 0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,17 +99,14 @@ pipeline {
|
|||||||
post {
|
post {
|
||||||
success {
|
success {
|
||||||
script {
|
script {
|
||||||
echo "✅ Vue3 SDK v${env.PUBLISH_VERSION} 构建成功 (Commit: ${env.GIT_COMMIT_SHORT})"
|
echo "Vue3 SDK v${env.PUBLISH_VERSION} 构建成功 (Commit: ${env.GIT_COMMIT_SHORT})"
|
||||||
if (params.PUBLISH) {
|
if (params.PUBLISH) {
|
||||||
echo "📦 已发布到 Nexus npm 仓库: ${NEXUS_REGISTRY}"
|
echo "已发布到 Nexus npm 仓库: ${NEXUS_REGISTRY}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
failure {
|
failure {
|
||||||
echo "❌ Vue3 SDK 构建失败,请检查日志"
|
echo "Vue3 SDK 构建失败,请检查日志"
|
||||||
}
|
|
||||||
always {
|
|
||||||
sh 'rm -f .npmrc 2>/dev/null || true'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户