2016-06-27 80 views
1

我正在使用Jenkins管理持续集成。我的一项工作包含下列任务:Jenkins的npm安装失败安装托管在bitbucket上的模块

  • 从克隆一个到位桶库通过Git的插件,使用证书“到位桶访问”(与密码私钥)=>工作正常!
  • 在存储库中执行批处理命令:'npm install'=>失败

在package.json文件中,有一些常见的nodeJS模块,如颜色,fs.extra等。如果它们是唯一的,那么它们将被正确安装。

但也有上到位桶托管私有模块:

"dependencies": { 
    "module": "git+ssh://[email protected]/<team>/module.git" 
} 

该模块发生故障时要安装“故宫安装”命令(见下文詹金斯日志)。

该作业在Windows 7从站上运行。如果我尝试在从机上的会话“mySession”上进行'npm install',它会要求我提供对应于位于C:\ Users \ mySession \ .ssh \ id_rsa(也具有BitBucket访问权)的私钥的密码,但特定于会话“mySession”,与“bitbucket访问权限”凭证不同)。然后'npm install'通过安装模块正常结束。

我尝试使用SSH Agent插件,凭证“bitbucket access”:它正确启动,但似乎之后不会使用,因为权限被拒绝。

你有什么想法如何解决这个问题,并使'npm安装'正常工作?

谢谢你的喉舌!

詹金斯登录:

Construction à distance sur MySlave in workspace C:\Jenkins\workspace 
[ssh-agent] Looking for ssh-agent implementation... 
[ssh-agent] Java/tomcat-native ssh-agent 
[ssh-agent] Registered BouncyCastle on the remote agent 
[ssh-agent] Started. 
[ssh-agent] Using credentials bitbucket access 

... 

npm WARN package.json [email protected] No description 
npm WARN package.json [email protected] No repository field. 
npm WARN package.json [email protected] No README data 
npm WARN addRemoteGit Error: Command failed: git -c core.longpaths=true config --get remote.origin.url 
npm WARN addRemoteGit 
npm WARN addRemoteGit  at ChildProcess.exithandler (child_process.js:203:12) 
npm WARN addRemoteGit  at emitTwo (events.js:87:13) 
npm WARN addRemoteGit  at ChildProcess.emit (events.js:172:7) 
npm WARN addRemoteGit  at maybeClose (internal/child_process.js:818:16) 
npm WARN addRemoteGit  at Socket.<anonymous> (internal/child_process.js:319:11) 
npm WARN addRemoteGit  at emitOne (events.js:77:13) 
npm WARN addRemoteGit  at Socket.emit (events.js:169:7) 
npm WARN addRemoteGit  at Pipe._onclose (net.js:469:12) 
npm WARN addRemoteGit git+ssh://[email protected]/<team>/module.git resetting remote C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-<team>-module-git-2a4d53e0 
because of error: { [Error: Command failed: git -c core.longpaths=true config --get remote.origin.url 
npm WARN addRemoteGit ] 
npm WARN addRemoteGit killed: false, 
npm WARN addRemoteGit code: 1, 
npm WARN addRemoteGit signal: null, 
npm WARN addRemoteGit cmd: 'git -c core.longpaths=true config --get remote.origin.url' } 
npm ERR! git clone --template=C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\_templates --mirror ssh://[email protected]/<team>/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-<team>-module-git-2a4d53e0: Cloning into bare repository 
'C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-<team>-module-git-2a4d53e0'... 
npm ERR! git clone --template=C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\_templates --mirror ssh://[email protected]/<team>/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-<team>-module-git-2a4d53e0: Permission denied (publickey). 
npm ERR! git clone --template=C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\_templates --mirror ssh://[email protected]/<team>/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-<team>-module-git-2a4d53e0: fatal: Could not read from remote repository. 
npm ERR! git clone --template=C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\_templates --mirror ssh://[email protected]/<team>/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-<team>-module-git-2a4d53e0: 
npm ERR! git clone --template=C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\_templates --mirror ssh://[email protected]/<team>/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-<team>-module-git-2a4d53e0: Please make sure you have the correct access rights 
npm ERR! git clone --template=C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\_templates --mirror ssh://[email protected]/<team>/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-<team>-module-git-2a4d53e0: and the repository exists. 
npm ERR! Windows_NT 6.1.7601 
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" 
npm ERR! node v4.2.3 
npm ERR! npm v2.14.7 
npm ERR! code 128 

npm ERR! Command failed: git -c core.longpaths=true clone --template=C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\_templates --mirror ssh://[email protected]/<team>/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-<team>-module-git-2a4d53e0 
npm ERR! Cloning into bare repository 'C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-<team>-module-git-2a4d53e0'... 
npm ERR! Permission denied (publickey). 
npm ERR! fatal: Could not read from remote repository. 
npm ERR! 
npm ERR! Please make sure you have the correct access rights 
npm ERR! and the repository exists. 
npm ERR! 
npm ERR! 
npm ERR! If you need help, you may report this error at: 
npm ERR!  <https://github.com/npm/npm/issues> 

... 

[ssh-agent] Stopped. 

可能是有用的:

  • 詹金斯版本:1.628
  • 证书插件:2.1.3
  • Git的插件:2.3.5
  • 的Git客户端插件:1.19.6
  • Bitbucket plugi N:1.1.2
  • SSH证书插件:1.12
  • SSH代理插件:1.13

回答

0

您需要generate an OAuth token在到位桶,看看创造消费者部分。然后,你可以用这样的HTTPS使用它:

"dependencies": { 
    "module": "git+https://x-token-auth:{access_token}@bitbucket.org/user/module.git" 
} 
+0

谢谢你的答案! 我像你说的那样在Bitbucket中生成了一个OAuth令牌。然后,如果我运行“git clone https:// x-token-auth: @ bitbucket.org/user/module.git”,它可以工作并克隆存储库,但是如果我运行“npm install”,它将失败错误:致命:无法找到'git + https'的远程助手。 你对这有什么想法吗? – Benoit

+0

@Benoit我唯一能找到的就是这个https://github.com/npm/npm/issues/9053但它已经很老了,一定已经被修复了。可以尝试更新你的npm到v3.7.0? –

+0

@Benoit这里是描述该功能的文档https://docs.npmjs.com/files/package.json#git-urls-as-dependencies,并且唯一的参考资料与Changelogs https: //github.com/npm/npm/blob/master/CHANGELOG.md在v3.7.0之后,所以尝试3.7 +版本的npm –

1

我曾在一个Jenkinsfile类似的问题,即npm将无法​​访问,即使我能做到这一点从命令行同一用户的私人混帐回购协议。好像.ssh/config被忽略。我可以用下面的代码片段解决这个问题Jenkinsfile

sh "eval \$(ssh-agent); ssh-add /home/tomcat/.ssh/mysshkey; npm install" 
+0

帮我这个问题,一些细节: 编辑文件的〜/ .ssh/config中 有了: 主机github.c om HostName github.com User git IdentityFile〜/ .ssh/ Nicolas