ddelizia
ddelizia

Reputation: 1571

Jenkins and Stash setup ssh key

I'm setting up jenkins and stash on the same server. Stash is working well through http. To let Jenkins connect to Stash I created a ssh (with the Jenkins user and the key is stored into /var/lib/jenkins/.ssh/id_rsa.pub). As the guide says I added this key to my profile and enabled ssh in Administartion>server settings.

In jenkins I installed the Git plugin and in the genarl configuration:

Global Config user.name Value

Global Config user.email Value

while in the project configuration i set up the following field:

Repository URL: ssh://[email protected]:7999/AT/repository1.git

If I run the job then I get the following error:

Building in workspace /var/lib/jenkins/jobs/Test Job/workspace
Checkout:workspace / /var/lib/jenkins/jobs/Test Job/workspace - hudson.remoting.LocalChannel@6bbef70
Using strategy: Default
Cloning the remote Git repository
Cloning repository ssh://[email protected]:7999/AT/repository1.git
git --version
git version 1.7.12.4
ERROR: Error cloning remote repo 'origin' : Could not clone ssh://[email protected]:7999/AT/repository1.git
hudson.plugins.git.GitException: Could not clone ssh://[email protected]:7999/AT/repository1.git
    at hudson.plugins.git.GitAPI.clone(GitAPI.java:273)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1044)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:986)
    at hudson.FilePath.act(FilePath.java:852)
    at hudson.FilePath.act(FilePath.java:825)
    at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:986)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1142)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1324)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:676)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:581)
    at hudson.model.Run.execute(Run.java:1518)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:236)
Caused by: hudson.plugins.git.GitException: Command "/home/danilo/libexec/git-core/git clone --progress -o origin ssh://[email protected]:7999/AT/repository1.git /var/lib/jenkins/jobs/Test Job/workspace" returned status code 128:
stdout: Cloning into '/var/lib/jenkins/jobs/Test Job/workspace'...

stderr: Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

    at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:897)
    at hudson.plugins.git.GitAPI.access$000(GitAPI.java:42)
    at hudson.plugins.git.GitAPI$1.invoke(GitAPI.java:269)
    at hudson.plugins.git.GitAPI$1.invoke(GitAPI.java:248)
    at hudson.FilePath.act(FilePath.java:852)
    at hudson.FilePath.act(FilePath.java:825)
    at hudson.plugins.git.GitAPI.clone(GitAPI.java:248)
    ... 14 more
Trying next repository
ERROR: Could not clone repository
FATAL: Could not clone
hudson.plugins.git.GitException: Could not clone
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1056)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:986)
    at hudson.FilePath.act(FilePath.java:852)
    at hudson.FilePath.act(FilePath.java:825)
    at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:986)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1142)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1324)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:676)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:581)
    at hudson.model.Run.execute(Run.java:1518)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:236)

Upvotes: 1

Views: 7912

Answers (2)

Nick N
Nick N

Reputation: 1048

I got the same exact error by having an invalid URL that typically looks like an SCP command, which is different from the git commands.

I originally had:

ssh://jenkins@machinename:~/repos/newrepo.git

And changed to:

ssh://jenkins@machinename/~/repos/newrepo.git

I was setting things up for jenkins. Once I got it working properly at the command line, then my job in Jenkins worked fine.

Upvotes: 0

Becca Gaspard
Becca Gaspard

Reputation: 1257

I had a similar problem - you need to add your stash server to known_hosts on your jenkins server.

Log onto your jenkins server and ssh to your stash server. This will add an entry for the stash server in your user's known_hosts file.

Then copy the known_hosts file to $JENKINS_HOME/.ssh and change the file owner to jenkins.

Upvotes: 3

Related Questions