ci: fix Jenkinsfile to use bat (Jenkins runs on Windows)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
父节点
6a356f246a
当前提交
7054cb7c4f
50
Jenkinsfile
vendored
50
Jenkinsfile
vendored
@ -1,11 +1,6 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
parameters {
|
|
||||||
string(name: 'VERSION', defaultValue: '', description: '发布版本号(留空使用 package.json 中的 version)')
|
|
||||||
booleanParam(name: 'PUBLISH', defaultValue: true, description: '是否发布到 Nexus npm 仓库')
|
|
||||||
}
|
|
||||||
|
|
||||||
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/xuqmGroup/XuqmGroup-H5SDK.git'
|
GIT_URL = 'https://xuqinmin.com/xuqmGroup/XuqmGroup-H5SDK.git'
|
||||||
@ -27,78 +22,69 @@ pipeline {
|
|||||||
userRemoteConfigs: scm.userRemoteConfigs
|
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()) {
|
env.PUBLISH_VERSION = bat(script: '@node -p "require(\'./package.json\').version"', returnStdout: true).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') {
|
stage('Build Info') {
|
||||||
steps {
|
steps {
|
||||||
echo "发布版本: ${env.PUBLISH_VERSION}"
|
echo "发布版本: ${env.PUBLISH_VERSION} (请确认已在 package.json 中更新版本号)"
|
||||||
echo "Git Commit: ${env.GIT_COMMIT_SHORT}"
|
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('Publish to Nexus') {
|
stage('Publish to Nexus') {
|
||||||
when {
|
|
||||||
expression { return params.PUBLISH }
|
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) {
|
withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) {
|
||||||
sh """
|
bat """
|
||||||
echo "//nexus.xuqinmin.com/repository/npm-hosted/:_auth=\$(echo -n '\${NPM_USER}:\${NPM_PASS}' | base64)" > .npmrc
|
powershell -NonInteractive -Command "Set-Content .npmrc ('//nexus.xuqinmin.com/repository/npm-hosted/:_auth=' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(\$env:NPM_USER + ':' + \$env:NPM_PASS))) -Encoding ASCII"
|
||||||
npm publish --registry ${NEXUS_REGISTRY}
|
npm publish --registry %NEXUS_REGISTRY%
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
sh 'rm -f .npmrc 2>/dev/null || true'
|
bat 'del .npmrc 2>nul || exit 0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Publish Private SDK to Nexus') {
|
stage('Publish Private SDK to Nexus') {
|
||||||
when {
|
|
||||||
expression { return params.PUBLISH }
|
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) {
|
withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) {
|
||||||
sh """
|
bat """
|
||||||
echo "//nexus.xuqinmin.com/repository/npm-hosted/:_auth=\$(echo -n '\${NPM_USER}:\${NPM_PASS}' | base64)" > .npmrc
|
powershell -NonInteractive -Command "Set-Content .npmrc ('//nexus.xuqinmin.com/repository/npm-hosted/:_auth=' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(\$env:NPM_USER + ':' + \$env:NPM_PASS))) -Encoding ASCII"
|
||||||
cp package.json package.json.bak
|
copy package.json package.json.bak
|
||||||
cp package.private.json package.json
|
copy package.private.json package.json
|
||||||
npm publish --registry ${NEXUS_REGISTRY}
|
npm publish --registry %NEXUS_REGISTRY%
|
||||||
mv package.json.bak package.json
|
move /Y package.json.bak package.json
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
sh 'rm -f .npmrc 2>/dev/null || true'
|
bat 'del .npmrc 2>nul || exit 0'
|
||||||
sh 'if [ -f package.json.bak ]; then mv package.json.bak package.json; fi'
|
bat 'if exist package.json.bak move /Y package.json.bak package.json'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户