diff --git a/Jenkinsfile b/Jenkinsfile index 8e59a90..a988e21 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,11 +1,6 @@ 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' @@ -27,78 +22,69 @@ pipeline { 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() + env.GIT_COMMIT_SHORT = bat(script: '@git rev-parse --short HEAD', returnStdout: true).trim() + env.PUBLISH_VERSION = bat(script: '@node -p "require(\'./package.json\').version"', returnStdout: true).trim() } } } stage('Build Info') { steps { - echo "发布版本: ${env.PUBLISH_VERSION}" + echo "发布版本: ${env.PUBLISH_VERSION} (请确认已在 package.json 中更新版本号)" echo "Git Commit: ${env.GIT_COMMIT_SHORT}" } } stage('Install Dependencies') { steps { - sh 'npm ci' + bat 'npm ci' } } stage('Type Check') { steps { - sh 'npm run type-check' + bat 'npm run type-check' } } stage('Build') { steps { - sh 'npm run build' + bat '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} + bat """ + 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% """ } } post { always { - sh 'rm -f .npmrc 2>/dev/null || true' + bat 'del .npmrc 2>nul || exit 0' } } } 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 + bat """ + 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" + copy package.json package.json.bak + copy package.private.json package.json + npm publish --registry %NEXUS_REGISTRY% + move /Y 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' + bat 'del .npmrc 2>nul || exit 0' + bat 'if exist package.json.bak move /Y package.json.bak package.json' } } }