Comment on page
Bitbucket is a version control and hosting service for Git repositories. It enables developers to store and manage code, collaborate on projects, and use features like pull requests and code review. Bitbucket also offers features for continuous integration and delivery (CI/CD) and integrates with various tools and services. It is available in different plans, including a free option for small teams and paid plans for larger teams and organizations.
You can sign up to Codesphere with your Bitbucket account, check out repositories, and automatically create preview deployments for each pull request.
Either sign up directly with your Bitbucket account or connect an existing account - both only take a few clicks. Once connected, you can browse your Bitbucket repositories in the create Workspace dialogue. Cloning a repository, building the code, and getting your application live can take as little as a few seconds (depending on the size of your app). Even larger applications can typically be live in a minute.
Bitbucket Integration in Codesphere "Create Workspace" Modal
Here is a step by step guide how to set up preview deployments for any Bitbucket repository
- 1.If you haven't done so already, create a Codesphere user with a username & password (OAuth won't work for using Bitbucket Pipelines) - we recommend creating a separate sysadmin user for this.
- 2.Log in to your new user and connect it to Bitbucket by clicking the "+ New Workspace" button and selecting "Connect Bitbucket" in the "Create Workspace" modal.Codesphere Create Workspace Modal
- 3.Ensure the connected Bitbucket account has access to the repository for which you are setting up the preview deployments.
- 5.Enable Pipelines for your Bitbucket account (requires 2FA to be set).
- 6.Create a Bitbucket access token with read & write access to the repo and pull requests.Bitbucket create Access Token
- 7.Navigate to repository
Settings/Pipelines/Repository variablesand add the following secrets to the repositories' environment variables - make sure to set the secured checkbox. You can find more information on which variables can be set below.Bitbucket Repository Variables
- 8.Create a
bitbucket-pipelines.ymlfile in the root of your repository and add the following code.image: atlassian/default-image:3pipelines:pull-requests:'**':- step:deployment: Testscript:- pipe: docker://ghcr.io/codesphere-cloud/codesphere-monorepo/integrations/bitbucket-ci:latestvariables:ACCESS_TOKEN: $ACCESS_TOKENEMAIL: $CODESPHERE_EMAILPASSWORD: $CODESPHERE_PASSWORDTEAM: My TeamPLAN: MicroENV: |testing=abc
The following are the variables you can use for your Repository variables. (*) = required variable.
After following this guide, your Pipeline will run on every pull request and create a Preview Deployment for you to review your changes. It will add a new comment to your Pull Request that includes the domain to your Preview Deployment:
Bitbucket Preview Deployment Comment on Pull Request
Important note: Unlike GitHub, Bitbucket currently does not support running CI workflows upon closing pull requests. We are working on a solution that will periodically check whether any pull request has been closed and delete the corresponding workspaces - until then you have to delete them manually in Codesphere.