"Not authorized" error in Push code to bitbucket - bitbucket

I am using jgit to push code to bitbucket. I am able to clone with ssh. But to push, i have to set the credentials provider - i tried all combinations like ("PRIVATE-TOKEN","Access token"), app-password, credentials and nothing is working. Could you please advise?

Related

Jenkins BitBucket integration broke suddenly

I have an onpremise Jenkins server setup with Blue Ocean. This is connecting to a BitBbucket cloud account. I haven't done any builds in a couple of months and when I went to Jenkins today it couldn't build any builds and the Scan Mutltibranch pipeline was failing as well.
Error is:
com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRequestException: HTTP request error. Status: 403: Forbidden.
{"type": "error", "error": {"message": "To make a call, you need to use an app password."}}
I've tried using an app password and my BitBucket user password and neither are working. When I try to create a new pipeline with either of these passwords I just get an "Invalid username and/or password" error.
I'm not sure if anything has changed with Jenkins (or a plugin) or with BitBucket.
Disabling 2 Factor Authentication has fixed the problem. I'm not sure why this was ok before and not now.

Cannot create Pipiline in BlueOcean, it got stuck on connection to Bitbucket stage with no errors

I am trying to create pipeline via BlueOcean, however creation got stuck at the connection stage despite there is no error on connection.
After choosing "Where is your Bitbucket Server?" and
Putting credentials to "Connect to Bitbucket"
Pressing button "connect" see icon that it progressing for a second, but it do not progress to next step.
No error messages. Credentials are definitely correct, I had tested with wrong credentials and saw "Invalid username and/or password"
Details for Bitbucket and Jenkins
I have admin rights in both Bitbucket and Jenkins
Bitbucket
Installed v5.8.0 for testing new version on my desktop http://pc_name.company.com:7990
It seems working ok, I can add users, create repo, clone repo in jenkins
Jenkins
ver. 2.89.3 as well installed at the same PC, working ok as well
Installed Blueocean plugin 1.4.2
Screenshot attached link to screenshoot
I was stuck in a similar situation. I'm selecting "Bitbucket Cloud" as the selected repository.
I resolved my issue by giving full access to "Generate Password" option in my Bitbucket - in case it helps someone else

Jenkins - git requests for login credentials using Git plugin

I have a couple of Jobs that pull code from bitbucket and build it in jenkins.
I'm using Git plugin to specify the repository URL + the git credentials.
Even though I set the credentials in each Job configuration, each time there is a push to bitbucket(that triggers the jenkins job), Mac is asking for "git-credential-osxkeychain wants to user the "login" keychain".
If I enter the password, the job will run and it will not ask again for a couple of hours.
I would like to make it permanent so that message won't be prompted any more.
Any advice ? thank you.
First, that only happens if you are using https URLs, as part of a git credential helper.
Using SSH URLs would bypass that entirely.
If the actual error message is
git-credential-osxkeychain wants to use your confidential information stored in "xxx" in your keychain.
Check out "unable to click always allow on git-credential-osxkeychain popup": delete the bitbucket entry, and do a git ls-remote /url/bitbucket/repo to force the credential helper to ask those credentials again: enter them, then try your Jenkins jobs again.

Bitbucket pull request builder plugin keeps triggering same commit build

I need to integrate Bitbucket with Jenkins. So that whenever a PR is opened it will trigger a build in Jenkins. Then commit status of the last commit in the PR will be updated as failed or success and this commit wont trigger the build again. (This works beautiful with Github but seems to be a nightmare for me with Bitbucket)
So far I did:
Installed Bitbucket pull request builder plugin.
Set everything up like its described in https://github.com/jenkinsci/bitbucket-pullrequest-builder-plugin#readme
User has write permissions to the repository (we added shh pub key to organization and its in the group that has write permissions)
Problems
Build is triggered over and over again for the same PR/commit
Commit status is not updated on bitbucket
Let me know if I can provide more information.
In my case, the Jenkins URL was set to http://jenkins:8080 and when such a URL was sent to BitBucket via their API, BitBucket returned the error "Invalid URL" (Look in Jenkins Logs: http://yourjenkins:8080/log/all) Which is not handled by the BitBucket Pull Request Builder plugin and thus kept continuously rebuilding all of our pull requests because it thought that build was not in progress. After setting Jenkins URL to http://jenkins.domain.tld:8080/ or http:///jenkins, the BitBucket API started accepting the URL and everything started to work.
But in your case it may be possible that some other error is the cause. You can check your Jenkins Error log to see the failure.
See the following issue: Build status notification fails with Enter a valid URL

Git plugin for Jenkins doesn't work with BitBucket repository

I have a project on bitbucket with git repository.
I want Jenkins job that pulls stuff from that repository. So I installed the Git Plugin.
I configure My Jenkins job to use git repository. I add credentials I use on BitBucket. Then I enter repository URL like this:
https://PawelRoman#bitbucket.org/PawelRoman/myproject.git
I'm getting the following error in red:
Failed to connect to repository : Failed to connect to https://PawelRoman#bitbucket.org/PawelRoman/myproject.git using credentials PawelRoman on BitBucket (status = 401)
401 seems like an authorization issue, but what can possibly be wrong? When I run git clone command manually from the server where I have Jenkins installed, using exactly the same repo URL and exactly the same credentials - it works without any issue. I am 100% sure the credentials are OK and repository URL is fine. How can I track down the cause of the issue?
Found out what the issue was. Repository URL was incorrect. For some reason jenkins git plugin does not allow for Username# in the repository URL.
So instead of https://PawelRoman#bitbucket.org/PawelRoman/myproject.git
You need to use
https://bitbucket.org/PawelRoman/myproject.git
And it will work.
User this url to get the project from the bitbucket
https://<user>:<pass>#bitbucket.org/<user>/<project>.git

Resources