来自Jenkins的npm安装无法安装在bitbucket上托管的模块

时间:2016-06-27 12:49:58

标签: git jenkins ssh npm credentials

我正在使用Jenkins来管理持续集成。我的一个工作包含以下任务:

  • 使用凭证" bitbucket access"从BitBucket通过Git插件克隆存储库(带密码的私钥)=>工作正常!
  • 在存储库中执行批处理命令:' npm install' =>失败

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

但是BitBucket上还有一个托管模块为私有模块:

"dependencies": {
    "module": "git+ssh://git@bitbucket.org/<team>/module.git"
}

(参见下面的Jenkins日志)。

作业在Windows 7从站上运行。如果我尝试安装&#39; npm install&#39;在一个会议&#34; mySession&#34;在奴隶上,它要求我提供与位于C:\ Users \ mySession \ .ssh \ id_rsa的私钥相对应的密码(它也具有BitBucket访问权限,但是特定于会话&#34; mySession&#34; ,和&#34; bitbucket access&#34;凭证不同。然后&#39; npm install&#39;通常通过安装模块结束。

我尝试使用SSH代理插件,凭据&#34; bitbucket access&#34; :它正确启动,但之后似乎没有使用,因为权限被拒绝。

您是否有任何想法如何解决此问题并进行&#39; npm安装&#39;工作正常吗?

感谢您的支持!

Jenkins日志:

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 deployment@1.0.0 No description
npm WARN package.json deployment@1.0.0 No repository field.
npm WARN package.json deployment@1.0.0 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://git@bitbucket.org/<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://git@bitbucket.org/<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://git@bitbucket.org/<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://git@bitbucket.org/<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://git@bitbucket.org/<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://git@bitbucket.org/<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://git@bitbucket.org/<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://git@bitbucket.org/<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.

可能有用:

  • Jenkins版本:1.628
  • 凭据插件:2.1.3
  • Git插件:2.3.5
  • Git客户端插件:1.19.6
  • Bitbucket插件:1.1.2
  • SSH凭据插件:1.12
  • SSH代理插件:1.13

2 个答案:

答案 0 :(得分:3)

我在Jenkinsfile中遇到了类似的问题,npm无法访问私有git repo,即使我可以从命令行以同一用户身份执行此操作。好像.ssh/config似乎被忽略了。我能够使用Jenkinsfile中的以下代码解决此问题:

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

答案 1 :(得分:0)

你需要在Bitbucket中generate an OAuth token,看看创建消费者部分。然后你可以像https这样使用它:

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