Prabhu Vignesh Rajagopal
Prabhu Vignesh Rajagopal

Reputation: 1068

How to add Bitbucket repository in to jenkins?

I have a ruby on rails code in bitbucket private repository. And i have added my repository remote into jenkins as follows:

https://bitbucket.org/myuser_name/demo_app

followed by Credentials:

Kind: username and password

and i have given bitbucket username and password into it.

Before i am saving the project configuration i got no error under Repository URL. So i thought i configured source code management correct. But when i am building the project i am getting this error.

Building in workspace /var/lib/jenkins/workspace/demo_app
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://bitbucket.org/myuser_name/demo_app # timeout=10
Fetching upstream changes from https://bitbucket.org/myuser_name/demo_app
 > git --version # timeout=10
using .gitcredentials to set credentials
 > git config --local credential.username myuser_name # timeout=10
 > git config --local credential.helper store --file=/tmp/git1159546302445779982.credentials # timeout=10
 > git -c core.askpass=true fetch --tags --progress https://bitbucket.org/myuser_name/demo_app +refs/heads/*:refs/remotes/origin/*
 > git config --local --remove-section credential # timeout=10
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://bitbucket.org/myuser_name/demo_app
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:810)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1066)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1097)
    at hudson.scm.SCM.checkout(SCM.java:485)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1269)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:607)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
    at hudson.model.Run.execute(Run.java:1738)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:410)
Caused by: hudson.plugins.git.GitException: Command "git -c core.askpass=true fetch --tags --progress https://bitbucket.org/myuser_name/demo_app +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: error: cannot fork() for git credential-store --file=/tmp/git1159545779982.credentials get: Cannot allocate memory
error: cannot fork() for /bin/echo: Cannot allocate memory
fatal: could not read Password for 'https://[email protected]': No such device or address

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1719)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1463)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:63)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:314)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:808)
    ... 11 more
ERROR: null
Finished: FAILURE

So where am i going wrong?

Upvotes: 1

Views: 382

Answers (2)

hewo
hewo

Reputation: 816

It would be better to include your project with deployment keys instead of username/password.

To add deployment keys to your bitbucket project go to https://bitbucket.org/myuser_name/demo_app/admin/deploy-keys/ .

Add your keys to Jenkins. On the project configuration page 'Source Code Management' -> 'Credentials' -> 'Add'. Choose 'SSH Username and privat key'. Add your username 'git' and your privat key.

Upvotes: 3

felipecamposclarke
felipecamposclarke

Reputation: 924

I do not know if today changed the way to do this, but some time ago I had to make a hook in Bitbucket to perform this task:

more info

Upvotes: 0

Related Questions