【问题标题】:Cannot publish node.js package using jenkins job无法使用 jenkins 作业发布 node.js 包
【发布时间】:2019-04-05 23:40:12
【问题描述】:

我需要创建一个 jenkins 作业以将包发布到 npmjs.com。包源代码在 github 仓库中。

我在控制台中执行“npm publish”命令成功地从我的电脑发布包,但使用 jenkins 时遇到错误。

这就是我在詹金斯工作中所拥有的:

  • github 项目的指定路径。

  • 添加了“执行 Windows 批处理命令”。脚本:

git checkout master
git pull
npm publish

控制台输出:

C:\Program Files (x86)\Jenkins\workspace\js-agent-cucumber-release>git checkout master 
Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
Previous HEAD position was fbd7040 Update package.json
Switched to branch 'master'

C:\Program Files (x86)\Jenkins\workspace\js-agent-cucumber-release>git pull 
Updating 27de403..fbd7040
Fast-forward
 package.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

C:\Program Files (x86)\Jenkins\workspace\js-agent-cucumber-release>npm publish 
npm notice 
npm notice package: reportportal-agent-cucumber@2.0.5
npm notice === Tarball Contents === 
npm notice 1.4kB  package.json                                                       
npm notice 49B    .eslintrc.js                                                       
npm notice 11.6kB LICENSE                                                            
npm notice 11.3kB README.md                                                          
npm notice 15.6kB modules/cucumber-epam-reportportal-handler.js                      
npm notice 191B   modules/index.js                                                   
npm notice 1.3kB  modules/loggerWorld.js                                             
npm notice 267B   testSample/config/rpConfig.json                                    
npm notice 1.4kB  testSample/cuceLaunch.js                                           
npm notice 234B   testSample/features/noStepDef.feature                              
npm notice 222B   testSample/features/passed.feature                                 
npm notice 285B   testSample/features/scenarioOutline.feature                        
npm notice 362B   testSample/features/step_definitions/support/handlers.js           
npm notice 139B   testSample/features/step_definitions/support/hooks.js              
npm notice 748B   testSample/features/step_definitions/support/world.js              
npm notice 2.5kB  testSample/features/step_definitions/waiting.js                    
npm notice 340B   testSample/features/table.feature                                  
npm notice 374B   testSample/features/webDriverFailed.feature                        
npm notice 327B   testSample/package.json                                            
npm notice 820B   testSample/protractor.conf.js                                      
npm notice 291B   testSample/protractor/features/failedProtractor.feature            
npm notice 184B   testSample/protractor/features/noSuchElementProtractor.feature     
npm notice 217B   testSample/protractor/features/protractor.feature                  
npm notice 954B   testSample/protractor/features/step_definitions/protractorSteps.js 
npm notice 368B   testSample/protractor/features/step_definitions/support/handlers.js
npm notice 136B   testSample/protractor/features/step_definitions/support/hooks.js   
npm notice 216B   testSample/protractor/features/step_definitions/support/world.js   
npm notice 6B     testSample/reports/report.json                                     
npm notice === Tarball Details === 
npm notice name:          reportportal-agent-cucumber             
npm notice version:       2.0.5                                   
npm notice package size:  15.3 kB                                 
npm notice unpacked size: 51.9 kB                                 
npm notice shasum:        478e6712549cfd3b0d472091409ef248625aa2e1
npm notice integrity:     sha512-NpE2GRG6a9YV7[...]DdxhC8MtZbISA==
npm notice total files:   28                                      
npm notice 
npm ERR! path C:\WINDOWS\TEMP\npm-9528-4708d294\tmp\fromDir-47da48b4\package.tgz
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'C:\WINDOWS\TEMP\npm-9528-4708d294\tmp\fromDir-47da48b4\package.tgz'
npm ERR!  { [Error: EPERM: operation not permitted, unlink 'C:\WINDOWS\TEMP\npm-9528-4708d294\tmp\fromDir-47da48b4\package.tgz']
npm ERR!   cause:
npm ERR!    { Error: EPERM: operation not permitted, unlink 'C:\WINDOWS\TEMP\npm-9528-4708d294\tmp\fromDir-47da48b4\package.tgz'
npm ERR!      errno: -4048,
npm ERR!      code: 'EPERM',
npm ERR!      syscall: 'unlink',
npm ERR!      path:
npm ERR!       'C:\\WINDOWS\\TEMP\\npm-9528-4708d294\\tmp\\fromDir-47da48b4\\package.tgz' },
npm ERR!   isOperational: true,
npm ERR!   stack:
npm ERR!    'Error: EPERM: operation not permitted, unlink \'C:\\WINDOWS\\TEMP\\npm-9528-4708d294\\tmp\\fromDir-47da48b4\\package.tgz\'',
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'unlink',
npm ERR!   path:
npm ERR!    'C:\\WINDOWS\\TEMP\\npm-9528-4708d294\\tmp\\fromDir-47da48b4\\package.tgz' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\npm-cache\_logs\2019-04-03T14_18_29_316Z-debug.log
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE

有没有人知道如何解决这个问题?

【问题讨论】:

    标签: javascript jenkins npm package publishing


    【解决方案1】:

    最后我设法创建了一个管道来将我的包发布到 npmjs。步骤:

    1. 创建一个“管道”类型的 jenkins 作业。

    2. 在“管道”部分选择“来自 SCM 的管道脚本”。

    3. 选择存储库类型并将路径添加到您的存储库。

    4. 在项目的根目录下添加一个名为“Jenkinsfile”的文件,并将以下脚本放入其中。

    pipeline {
    
        agent {
    
            docker {
                image 'node:10-alpine' 
                args '-u root' 
            }
        }
    
        stages {
    
            stage('Install') { 
                steps {
                    sh 'npm install' 
                }
            }
            stage('Publish') { 
    
                steps {
    
                    load "$JENKINS_HOME/jobvars.env"
    
                    withEnv(["TOKEN=${NPMJS_TOKEN}"]) {
    
                        sh 'echo "//registry.npmjs.org/:_authToken=${TOKEN}" >> ~/.npmrc'
                        sh 'npm publish' 
    
                    }
                }
            }
        }
    }
    
    1. 在安装 jenkins 的文件夹下创建一个名为“jobvars.env”的文件,并 把线放进去:
    NPMJS_TOKEN="token-generated-on-npmjs-com-in-your-profile"
    

    【讨论】:

      猜你喜欢
      • 2014-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-21
      • 1970-01-01
      • 2021-11-22
      • 1970-01-01
      相关资源
      最近更新 更多