Daniel Caldera
Daniel Caldera

Reputation: 1119

Jenkins pipeline private repository dependency

I have a Jenkins pipeline in a repository, and the package.json of this repository have a dependency from another repository (Both are Bitbucket private repositories). When I do the yarn install in local, it works perfectly, but in jenkins it's fail with this error:

yarn install v1.2.1
[1/5] Validating package.json...
[2/5] Resolving packages...
error Command failed.
Exit code: 128
Command: git
Arguments: ls-remote --tags --heads ssh://[email protected]/user/repo.git
Directory: /var/lib/jenkins/workspace/s_repo_branch-
YJRVO7LRN3U452ZV2XNZJUB35FGSW2NXEAUPBCDKUVTKUFAHHBDA
Output:
Permission denied (publickey).
fatal: Could not read from remote repository.

I had added the ssh key on the host machine, added as jenkins credentials for scan organization folder(using the Bitbucket Branch Source Plugin) and added the key too in both bitbucket project. The pipeline of the other project (that don't had depedencies) works correctly, so I don't think that it will a problem of the ssh key. The line of the dependency in the package.json looks like:

"repo": "ssh://bitbucket.org/user/repo.git#develop"

Also tried

"repo": "git+ssh://bitbucket.org/user/repo.git#develop"

Any had similar issue?

Upvotes: 4

Views: 1938

Answers (2)

VonC
VonC

Reputation: 1326792

When I do the yarn install in local, it works perfectly, but in jenkins it's fails

That is typical of a git which is not searched where you expect too (should be in the account running Jenkins/.ssh)

A good way to debug this is to set the variable GIT_SSH_COMMAND=ssh -v (with the JENKINS EnvInject Plugin) in order to see, whenever git is called with ssh protocol, what keys are used.

The OP adds:

I have chosen to delete the passphrase from the ssh key and it works correctly.

that suggests the ssh-agent that would cache the passphrase was running in the user account, but not in the Jenkins account.

Upvotes: 1

Daniel Caldera
Daniel Caldera

Reputation: 1119

Thanks VonC message, I debugging jenkins with:

ssh -v bitbucket.org

I could be able to see that the problem was that jenkins tries to launch a tty to ask the passphrase

debug1: read_passphrase: can't open /dev/tty: No such device or address

Finally I have chosen to delete the passphrase from the ssh key and it works correctly.

Upvotes: 0

Related Questions