youngmon/atlassian-qna huggingface dataset:
Branch restriction - custom settings changes via API
Asked by Elena Dzhordzhilova:

Dear Bitbucket Community,

I have a question regarding branch restrictions - I created new branch restriction via the API. The group which I white listed for push has also rights to delete or rewrite the branch. If the restriction is created via the interface, those settings are not marked by default and I would want to disable them via the API. I looked for flags, related with the custom settings, where they appear when are in use, but I did not find anything. This is the payload which I use with POST request to create the branch restriction:  

```
{
        "type": "branch",
        "branch_match_kind": "glob",

        "users": [],
        "groups": [
            {
                "slug": "my-team",
                "type": "group"

            }
        ],
        "kind": "push",
        "pattern": "elena-branch",
    }
)
```

<br />

Even with default_permission and account_privilege flag, the permissions for delete and rewrite branch histrory are still active:  

```
{
    "branch_match_kind": "glob",
    "groups": [{
        "default_permission": "read",
        "account_privilege": "read",
        "name": "my-team",
        "slug": "my-team",
        "type": "group"
    }],
    "kind": "push",
    "pattern": "elena-branch"
}
```


Answers:
author: Mark C
body: Hi [@Elena Dzhordzhilova](/t5/user/viewprofilepage/user-id/5182918),

Thank you for reaching out to the community.

I understand that you'd like to uncheck the two branch restriction settings below via API:

* "Allow rewriting branch history"
* "Allow deleting this branch"

If that's correct, you can uncheck those settings by running two POST commands specifically changing the parameter "kind":

To uncheck "Allow rewriting branch history", you can use the CURL command below:

```
curl -u bb_username:app_password -X POST -k -H 'Content-Type: application/json; charset=utf-8' --data '{"kind": "force", "branch_match_kind": "glob", "pattern": "elena-branch"}' https://api.bitbucket.org/2.0/repositories/workspace_id/repo_name/branch-restrictions
```

To uncheck "Allow deleting this branch", you can use the CURL command below:

```
curl -u bb_username:app_password -X POST -k -H 'Content-Type: application/json; charset=utf-8' --data '{"kind": "delete", "branch_match_kind": "glob", "pattern": "elena-branch"}' https://api.bitbucket.org/2.0/repositories/workspace_id/repo_name/branch-restrictions
```

I hope it helps and let me know how it goes.

Regards,  
Mark C

comments: author: Elena Dzhordzhilova
body: Hello [@Mark C](/t5/user/viewprofilepage/user-id/1210823) !

Thank you a lot for the help!

Both POST commands worked as expected and the functionalities are disabled for the desired branch!

Best Regards,

Elena


Tags: bitbucket-cloud

cloud
/browse/{path} PUT endpoint is not working as expected
Asked by Hemant Kumar:

Hi All,

I was using /browse/{path} put endpoint to create and update file.

it was working fine till yesterday.

from today I see create functionality is not working and it's giving 500 error

fatal : path file does not exist

but update functionality is working fine .

could you please help if something has change ?

Endpoint details can be found here : <https://docs.atlassian.com/bitbucket-server/rest/6.4.0/bitbucket-rest.html#idp188>


Answers:
author: Vladislav Markin
body: Downgrade git on server: v2.35.0 or less


Tags: bitbucket-server

server
Resource not found, but it is there
Asked by Julien Masson-Ratel:

When I go on to look at the source of a branch in bitbucket, let's say master, it finds the file but when I click on it, it says Resource not found. I obviously can still look at the history with git, but I like the way it is presented on bitbucket. Any idea why this might be happening?

For additional information, bitbucket cuts the display at 500 files. The first 500 work correctly and display the content, but when I search for something that would be a file after the first 500, even if filtered, it does not work![Screenshot 2023-09-21 082228.png](/t5/image/serverpage/image-id/282039i90950552F65D49F8/image-size/large?v=v2&px=999 "Screenshot 2023-09-21 082228.png")  
![Screenshot 2023-09-21 082326.png](https://community.atlassian.com/t5/image/serverpage/image-id/282040i967280A83B971611/image-size/large?v=v2&px=999 "Screenshot 2023-09-21 082326.png")  
![Screenshot 2023-09-21 082339.png](/t5/image/serverpage/image-id/282037i8A911728770DC03D/image-size/large?v=v2&px=999 "Screenshot 2023-09-21 082339.png")


Answers:
author: Ben
body: Hi Julien,

Are you able to try to filter the results using a different browser with all add-ons disabled (or Incognito if using Chrome)? If you still encounter issues, please also clear the browser cache.

If you still do not have any luck, I will raise a support ticket on your behalf as we need you to share a HAR log (which would not be appropriate on a public forum).

Cheers!

- Ben (Bitbucket Cloud Support)

comments: author: Julien Masson-Ratel
body: Hi, nothing has changed and it does work now. I guess it was a temporary issue. Thanks


Tags: bitbucket-cloud

cloud
Branches disappeared
Asked by stas never:

Hi there,  
i have this repository for a long time,  
I had a break for a few months with commiting and pushing code,  
Today i've logged in after a few months and the repo looks like it been updated last time on June 2022.  
Can someone check this issue please ? its very urgent.  

thx.  


Answers:
author: Mark C
body: Hi [@stas never](/t5/user/viewprofilepage/user-id/5322669),

Welcome to the community.

A possible reason why branches may disappear in a repository could be either branches were merged and closed (or deleted) or they were intentionally deleted.

For those branches that disappeared, if you still have them locally, you can try to push them back to the remote repository following our knowledge-based article here: [How to restore a deleted branch](https://confluence.atlassian.com/bbkb/how-to-restore-a-deleted-branch-765757540.html)

Regards,  
Mark C


Tags: bitbucket-cloud

cloud
How can I use atlassian accounts in BitBucket (A user with that username already exists)?
Asked by Marcus Punzelt:

Hello,

the procedure to connect to jira is described in this article <https://confluence.atlassian.com/bbkb/creating-a-bitbucket-cloud-account-1206558490.html>.

Then I go to the account management (BitBucket) and add a user, same email, as atlassian account. Then I am supposed to invite the user. But here is the problem. When inviting, I get a message that the username already exists.  
How do I create a correct connection between the accounts in BitBucket and Atlassian?

Thanks for the help!


Answers:
author: Syahrul
body: G'day [@Marcus Punzelt](/t5/user/viewprofilepage/user-id/5322599)

Welcome to the community!

Based on your description, you're encountering an issue while trying to register for a Bitbucket account with a username already in use. This results in the error message "A user with that username already exists."

Unfortunately, in Bitbucket cloud, usernames are assigned on a first-come, first-served basis. If someone has already taken the username you want, you won't be able to use it. Therefore, you must select a different username when registering with Bitbucket cloud.

Please note that your username choice won't affect your integration between Bitbucket cloud and Jira.

I hope this helps.

comments: author: Marcus Punzelt
body: Thank you, it worked. That means that the username must be cloud wide unique and not related to the used users in the organization.


Tags: bitbucket-cloud

cloud
how to switch the branch with bitbucket api in laravel
Asked by hemant kumar:

please give me answer


Answers:
author: Theodora Boudale
body: Hi Hemant and welcome to the community.

You can find the documentation for Bitbucket Cloud API here:

* <https://developer.atlassian.com/cloud/bitbucket/rest/intro/>

However, it is not clear what you mean by "switch the branch". If you're working on a clone of a repo and you want to switch branches, you can do this with the **git checkout** command. The API does not operate on a clone but on the remote Bitbucket repo. Do you perhaps want to change the repo's main branch (that is set from **Repository settings \> Repository details \> ADVANCED \> Main branch**)? Or something different?

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud
Unable to execute PHP's HTTP tests on pipelines
Asked by Alysson H_:

Good morning,

We want to configure a pipeline for one of our projects, we are occuring an issue related to Bitbucket's Pipeline.

On a given step, we want to perform tests:

* units tests are fine and all of them are good
* every test which run a HTTP request fails each time.

There is our step:

```
- step: &Tests
    name: Build Prisma to perform tests
    service:
      - docker
    cache:
      - composer
      - docker
    script:
      - eval $(cat secrets.def | sed 's/^/export /')
      - pecl install xdebug
      - docker-php-ext-enable xdebug
      - export XDEBUG_MODE=coverage
      - >-
        curl -sSL https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions -o - | sh -s \
        zip
      - cp .env.testing .env
      - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
      - composer install
      - export APP_URL="http://host.docker.internal:8000"
      - php artisan key:generate
      - php artisan migrate
      - php artisan optimize && php artisan optimize:clear
      - echo "memory_limit = 512M" > $PHP_INI_DIR/conf.d/php-memory-limits.ini
      - php artisan test --coverage
    artifacts:
      - secrets.def
```

And this is the result:

![Screenshot from 2023-09-21 11-58-15.png](/t5/image/serverpage/image-id/281996iED6BD7D473A133F5/image-size/large?v=v2&px=999 "Screenshot from 2023-09-21 11-58-15.png")

We watched on host.docker.internal (it changes nothing), also increase the available memory, same result.

I hope there is someone to help us.

Thank you,

Alysson


Answers:
author: Theodora Boudale
body: Hi Alysson,

Based on the output you posted here, the error seems to be related to your source code rather than an issue with Pipelines.

At the end of the screenshot, the following error is mentioned

```
TypeError: Unsupported operand types: string * int in <...>
```

along with the path of a file. I would suggest starting by checking this specific file.

**/opt/atlassian/pipelines/agent/build** is the path where the repo is cloned in the Docker container where the build is running. The rest should be the path of this file in your repo unless you generate this file during the build.

Kind regards,  
Theodora

comments: author: Alysson H_
body: Hello [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086)

Thank you for your answer, I was in holidays, my collegues did read your response and continue digging. They find a difference between development branch and our pipelines ; an environment variable was empty for PHP (SESSION_LIFETIME).

They also seperated php's server and vite too, the first one was not running because \`npm run dev\` took priority. It works fine now.

Thank you


author: Theodora Boudale
body: Thank you for the update Alysson, it's good to hear that the issue is resolved now!


Tags: bitbucket-cloud

cloud
Error message "Something went wrong on display"
Asked by Efe Osahon:

I am having issues in viewing my repositories and branches they are all showing this message: "

### Something went wrong {#toc-hId-2062448059}

Wait a few moments, then try again. If this keeps happening, check the current operational status of Bitbucket Cloud at [bitbucket.status.atlassian.com](https://bitbucket.status.atlassian.com/)

`9f79f041ed5c4a898be40330cd71a37a`

If the problem persists, contact Support and include the code displayed above, if one is provided.

"


Answers:
author: Ben
body: Hi Efe,

Please clear your browser cache and try to load this again, if this does not work - try to load your repository in a different browser with all add-ons disabled (or Incognito mode if using Chrome) and let me know how this goes.

If the browser is not the issue, I will need to raise a ticket on your behalf so we can look into this further.

Cheers!

- Ben (Bitbucket Cloud Support)

comments: author: Efe Osahon
body: Thanks a lot Ben. clearing my browser cache worked perfectly. I can access it all again. I'm grateful.


Tags: bitbucket-cloud

cloud
Can we store a file as secret in bitbucket, where all the secret variables could be defined ?
Asked by Shishir Mathur:

As per what's mentioned in the doc -

<https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/>

There is no way mentioned to store all the secret variables in a single file and then expose that file altogether to the pipeline.

Defining each variable as a separate secrets means we need to update the pipeline script every time a new variable is added. However, if there were a file to hold all the secrets and dynamically expose all those secret variables, we won't need to update the script every time a new variable is added.

FWIW, this is similar to to what is followed in case of Flutter -

Individually defining each variable -

```
--dart-define=someVariable=someValue --dart-define=otherVariable=otherValue --dart-define=thirdVariable=thirdValue
```

VS

Defining them all in one file -

```
--dart-define-from-file=<use-define-config.json>
```

So, is there a way to achieve the similar thing (to **dart-define-from-file**) in bitbucket secrets ?


Answers:
author: Theodora Boudale
body: Hi Shishir and welcome to the community!

I'm afraid that this is not possible at the moment.

You mention the following:
> Defining each variable as a separate secrets means we need to update the pipeline script every time a new variable is added. However, if there were a file to hold all the secrets and dynamically expose all those secret variables, we won't need to update the script every time a new variable is added.

I don't understand how using a file to hold all secrets would eliminate the need to edit the pipeline script. Even if the secret file solution were possible, wouldn't you still need to edit the pipeline script to reference the new variable? Could you please clarify what you mean, perhaps with an example?

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud
Webook HTTP status -2
Asked by Mark Kabana:

Have had a webhook setup for years that has been working fine on the repo:push action.

A few weeks ago the webhook started failing with HTTP status -2

Nothing changed and can't find any reason why this is happening.

There is no documentation available for this error.

We have simulated sending the request to our server using Postman with no issues.

So issue is with Bitbucket server sending webhook.

Can someone from the Bitbucket team please let us know what this error means and how to resolve?

Thanks!


Answers:
author: Theodora Boudale
body: Hi Mark,

A few weeks ago we made changes that affected the list of TLS Ciphers supported by webhook requests:

* <https://bitbucket.org/blog/updated-list-of-tls-cipher-suites-for-webhook-requests>

If your webhook started failing around the same time, you may be affected by this change.

You can find the list of supported cipher suites here:

* <https://support.atlassian.com/security-and-access-policies/docs/supported-security-protocols-for-atlassian-cloud-products/#Supported-cipher-suites>

Could you please review the web server's configuration and ensure it is configured to support one of the supported ciphers?

Kind regards,  
Theodora


author: Jimmy.Diep
body: Try enabling the logs for the webhook

repos -\> repository settings -\> webhooks -\> view request logs

comments: author: Mark Kabana
body: I have the request logs enabled...by viewing the log entries this is how i am able to tell that the HTTP Status is -2 - have no idea what a -2 status code means...

Any other ideas?


Tags: bitbucket-cloud

cloud
Execute hourly job only when there are commits
Asked by Sathya Kavacheri:

Hi,

I have an hourly pipeline job. Currently it runs every hour even when **no** checkin has been made. Is it possible for the hourly job to be executed only when a change has been checked in ? I tried the condition -\> changesets -\> includePaths \& it didn't help.

Here's the snippet of my bitbucket-pipelines.yml.

* The hourly job uses the custom:scheduled
* The custom:default is for on-demand builds.

```
definitions:
  steps:
    - step: &build
      max-time: 30 # set a 30 minute timeout
      name: Build & Test
      size: 2x
      caches:
        - gradle

      script:
        - utils/build-scripts/setup-image.sh
        - BASH_ENV=utils/build-scripts/bashrc bash ./gradlew -no-daemon dist
        - utils/build-scripts/upload-distribution.sh


pipelines:
  custom:
    default: # runs even with no change
      - step: *build

  scheduled: # runs this only on a schedule & only if there are changes
    - step: *build
      condition:
        changesets:
          includePaths:
            # run only when any changes found
            - "**"
```

Thanks!


Answers:
author: Theodora Boudale
body: Hi Sathya!

I'm afraid that this is not possible at the moment. The condition -\> changesets -\> includePaths is not going to work, because what it does is check if the commit that the build is running for has changes in the files you specified. It won't check for changes since the last build.

We have an open feature request for what you are asking:

* <https://jira.atlassian.com/browse/BCLOUD-22413>

Please make sure to add your vote (by selecting the **Vote for this issue** link) as the number of votes helps the development team and product managers better understand the demand for new features.

You are more than welcome to leave any feedback, and you can also add yourself as a watcher (by selecting the **Start watching this issue** link) if you'd like to get notified via email on updates. Implementation of new features is done as per our policy [here](https://confluence.atlassian.com/support/implementation-of-new-features-policy-201294576.html) and any updates will be posted in the feature request.

Please feel free to let me know if you have any questions.

Kind regards,  
Theodora


Tags: bitbucket-cloud

bitbucket-pipelines

cloud
Pipelines for Git Deploy
Asked by Nick C:

I've been deploying through pipelines for a couple years with no issues. All of a sudden - none of my repos deploy.

This is the error I'm getting:

```
curl: (60) SSL peer certificate or SSH remote key was not OK
More details here: https://curl.haxx.se/docs/sslcerts.html
```

I've checkout the url: <https://curl.haxx.se/docs/sslcerts.html> - but I can't understand it. Any help?


Answers:
author: Theodora Boudale
body: Hi Nick,

What is the command you are running in the Pipelines build, that shows this error?

Could you also post the full output of this command (after sanitizing private/sensitive data, if any)?

Kind regards,  
Theodora


Tags: bitbucket-cloud

bitbucket-pipelines

cloud

sftp
How to get the PR for a branch from the command line
Asked by Ari Sweedler:

When I push to a remote branch that has a PR open, bitbucket responds with

```
remote:
remote: View pull request for feature => main:
remote: https://stash.my_company.io/projects/my_proj/repos/my_code/pull-requests/1234
remote:
```

I can parse this output and \`open '<https://stash.my_company.io/projects/my_proj/repos/my_code/pull-requests/1234>'\` from the command line.

However, if I don't have anything to push but I still want to open up my PR from the command line, I cannot figure out how to do it.

\*\*\*

I want to be able to learn what PR my current branch has open. How to ask the server this?


Answers:
author: Ari Sweedler
body: I have a script that helps me open up a PR from the command line.

```
#!/bin/bash
function browser_pr_for_current_branch_in_pwd_stash() {
  local spec repo branch
  if ! branch="$(git branch --show-current)"; then
    echo "ERROR"
    return 1
  fi

  # We want to extract the "spec" and "repo", then prepend 'users' or
  # 'projects' to them depending on what type of repo it is (use the tilde to
  # determine this)
  IFS="," read -r spec repo < <(git remote -v | awk -F '[/ ]' '/fetch/ {print $4 "," $5}')
  repo="${repo%.git}"
  case "$spec" in
    ~*) spec="users/$(tr -d '~' <<< "$spec")" ;;
    *) spec="projects/$(tr 'a-z' 'A-Z' <<< "$spec")" ;;
  esac

  # Build the URL and return the answer
  echo "https://my_company.ilabs.io/${spec}/repos/$repo/compare/commits?sourceBranch=refs/heads/$branch"
}

if url="$(browser_pr_for_current_branch_in_pwd_stash "$PWD")"; then
  open "$url"
fi
```

And I invoke it like so:

```
git pr
```

But what I'd like is that I could first query the server and see if there is already a PR open before trying to create a new one.


Tags: bitbucket-server

server
How can I trigger email notification on Pipeline build failure using the Email Notify pipe?
Asked by yosser_mahfoudh:

How do I add the logic to a pipe to check the build exit code and only send email upon failure?


Answers:
author: yosser_mahfoudh
body: I'm using the same script, but even the status is success the email is sent BUt I want onlt the email be sent when the step before is failed.

Otherwise how can I use my company email (generated from Mircosoft 365) to sen the email?


author: Patrik S
body: Hello [@yosser_mahfoudh](/t5/user/viewprofilepage/user-id/3803216) and welcome to the Community!

You can use the pipeline [default environment variable](https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/#Default-variables) *BITBUCKET_EXIT_CODE* :
> The exit code of a step, can be used in after-script sections. Values can be 0 (success) or 1 (failed)

to create an **if** condition and check if the step is successful or not.

Following is an example of using that variable, along with the [**atlassian/email-notify**](https://bitbucket.org/product/features/pipelines/integrations?search=email&p=atlassian/email-notify), to send email notifications with the build status :

```
pipelines:
  default:
      - step:
          name: Build and Test
          script:
            - echo "abc"
          after-script:
            - ALERT_TYPE="success"
            - if [[ $BITBUCKET_EXIT_CODE -ne 0 ]]; then ALERT_TYPE="error" ; fi
            - pipe: atlassian/email-notify:0.10.0
              variables:
                USERNAME: 'myemail@example.com'
                PASSWORD: $PASSWORD
                FROM: 'myemail@example.com'
                TO: 'example1@example.com'
                HOST: 'smtp.gmail.com'
                SUBJECT: '${ALERT_TYPE}:Bitbucket Pipe Notification for ${BITBUCKET_BRANCH}'
```

For further instructions on how to configure the variables required to execute that pipe, you can refer to its official documentation below :

* [atlassian/email-notify \| Bitbucket Cloud](https://bitbucket.org/product/features/pipelines/integrations?search=email&p=atlassian/email-notify)

Hope that helps! Let me know in case you have any questions.

Thank you, [@yosser_mahfoudh](/t5/user/viewprofilepage/user-id/3803216) !

Patrik S


Tags: bitbucket-cloud

cloud