npm install from Jenkins fails installing module hosted on bitbucket
<p>I am using Jenkins to manage continuous integration. One of my jobs contains the following tasks :</p>

<ul>
<li>Cloning a repository from BitBucket through the Git plugin, using credential "bitbucket access" (private key with passphrase) => works fine !</li>
<li>Executing batch command in the repository : <strong>'npm install' => fails</strong> !</li>
</ul>

<p>In the package.json file, there are some common nodeJS modules like colors, fs.extra, etc. Those are correctly installed if they are the only ones.</p>

<p>But there is also a module hosted on BitBucket as private :</p>

<pre><code>"dependencies": {
    "module": "git+ssh://git@bitbucket.org/&lt;team&gt;/module.git"
}
</code></pre>

<p><strong>That module fails to be installed during the 'npm install' command</strong> (see Jenkins log below).</p>

<p>The job is run on a Windows 7 slave. If I try to make 'npm install' on a session "mySession" on the slave, it asks me for the passphrase corresponding to the private key located at C:\Users\mySession\.ssh\id_rsa (which has BitBucket access too, but which is specific to the session "mySession", and so different from the "bitbucket access" credential). Then 'npm install' ends normally by installing the module.</p>

<p>I tried to use the SSH Agent plugin, with the credential "bitbucket access" : it starts correctly, but it seems not to be used afterward, as the permission is denied.</p>

<p>Do you have any ideas how to resolve this problem and make the 'npm install' work correctly ?</p>

<p>Thank you for your aswers !</p>

<p>Jenkins log :</p>

<pre><code>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.&lt;anonymous&gt; (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/&lt;team&gt;/module.git resetting remote C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-&lt;team&gt;-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/&lt;team&gt;/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-&lt;team&gt;-module-git-2a4d53e0: Cloning into bare repository
'C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-&lt;team&gt;-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/&lt;team&gt;/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-&lt;team&gt;-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/&lt;team&gt;/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-&lt;team&gt;-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/&lt;team&gt;/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-&lt;team&gt;-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/&lt;team&gt;/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-&lt;team&gt;-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/&lt;team&gt;/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-&lt;team&gt;-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/&lt;team&gt;/module.git 
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-&lt;team&gt;-module-git-2a4d53e0
npm ERR! Cloning into bare repository 'C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_git-remotes\ssh-git-bitbucket-org-&lt;team&gt;-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!     &lt;https://github.com/npm/npm/issues&gt;

...

[ssh-agent] Stopped.
</code></pre>

<p>May be usefull :</p>

<ul>
<li>Jenkins version : 1.628</li>
<li>Credentials plugin : 2.1.3</li>
<li>Git plugin : 2.3.5</li>
<li>Git client plugin : 1.19.6</li>
<li>Bitbucket plugin : 1.1.2</li>
<li>SSH Credentials plugin : 1.12</li>
<li>SSH Agent plugin : 1.13</li>
</ul>