'Jenkins Unable to connect to Bitbucket cloud

I am setting up project in Jenkins where I have to pull code from bitbucket cloud.

I am seeing errors in Jenkins. Thing is Jenkins is unable to connect to bitbucket cloud.

Environment
Jenkins : Internally hosted ; http://jenkinsserver:8080
Bitbucket cloud : https://bitbucket.org/
Git plugin version:3.5.1

Logs from Jenkins

Started by user admin
[EnvInject] - Loading node environment variables.
Building in workspace /var/lib/jenkins/workspace/AccessbitbucketCloud
 > /opt/git/git-2.14.1/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > /opt/git/git-2.14.1/git config remote.origin.url https://bitbucket.org/myid/testpublicrepo.git # timeout=10
Fetching upstream changes from https://bitbucket.org/myid/testpublicrepo.git
 > /opt/git/git-2.14.1/git --version # timeout=10
using GIT_ASKPASS to set credentials For bitbucket Cloud
Setting http proxy: jenkinsserver:8080
 > /opt/git/git-2.14.1/git fetch --tags --progress https://bitbucket.org/myid/testpublicrepo.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://bitbucket.org/myid/testpublicrepo.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:817)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1084)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1115)
    at hudson.scm.SCM.checkout(SCM.java:495)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1276)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:560)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:485)
    at hudson.model.Run.execute(Run.java:1735)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:405)
Caused by: hudson.plugins.git.GitException: Command "/opt/git/git-2.14.1/git fetch --tags --progress https://bitbucket.org/myid/testpublicrepo.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: fatal: unable to access 'https://bitbucket.org/myid/testpublicrepo.git/': Received HTTP code 407 from proxy after CONNECT

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1924)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1643)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:71)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:352)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:815)
    ... 11 more
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE


Solution 1:[1]

Looks like you are using a proxy to connect to the Bitbucket cloud. Have you tried doing a git clone of this repository on the jenkins server (using the command line shell)?

stderr: fatal: unable to access 'https://bitbucket.org/myid/testpublicrepo.git/': Received HTTP code 407 from proxy after CONNECT

It looks like a the proxy is not able to connect to the bitbucket cloud. HTTP 407 is proxy authentication error. This is a good thread about git connection over proxy for jenkins.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1