2016-06-27 113 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