fix: generate npm auth via PowerShell to bypass Jenkins Groovy sandbox

这个提交包含在:
XuqmGroup 2026-05-16 12:25:32 +08:00
父节点 987e4f5952
当前提交 191d742591

18
Jenkinsfile vendored
查看文件

@ -38,11 +38,10 @@ pipeline {
stage('Install Dependencies') { stage('Install Dependencies') {
steps { steps {
withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) { withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) {
script { bat """
def auth = (NPM_USER + ':' + NPM_PASS).bytes.encodeBase64().toString() powershell -NonInteractive -Command "\$auth=[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(\$env:NPM_USER+':'+\$env:NPM_PASS)); @('@xuqm:registry=https://nexus.xuqinmin.com/repository/npm-hosted/','//nexus.xuqinmin.com/repository/npm-hosted/:_auth='+\$auth) | Set-Content .npmrc"
writeFile file: '.npmrc', text: "@xuqm:registry=https://nexus.xuqinmin.com/repository/npm-hosted/\n//nexus.xuqinmin.com/repository/npm-hosted/:_auth=${auth}\n" npm install --legacy-peer-deps
bat 'npm install --legacy-peer-deps' """
}
} }
} }
} }
@ -67,11 +66,10 @@ pipeline {
stage('Publish to Nexus') { stage('Publish to Nexus') {
steps { steps {
withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) { withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) {
script { bat """
def auth = (NPM_USER + ':' + NPM_PASS).bytes.encodeBase64().toString() powershell -NonInteractive -Command "\$auth=[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(\$env:NPM_USER+':'+\$env:NPM_PASS)); @('@xuqm:registry=https://nexus.xuqinmin.com/repository/npm-hosted/','//nexus.xuqinmin.com/repository/npm-hosted/:_auth='+\$auth) | Set-Content .npmrc"
writeFile file: '.npmrc', text: "@xuqm:registry=https://nexus.xuqinmin.com/repository/npm-hosted/\n//nexus.xuqinmin.com/repository/npm-hosted/:_auth=${auth}\n" npm publish --workspaces --registry %NEXUS_REGISTRY%
bat "npm publish --workspaces --registry %NEXUS_REGISTRY%" """
}
} }
} }
post { post {