- Creating a new environment when a branch is created or a pull request is opened.
- Rebuilding the environment when new code is pushed to Bitbucket.
- Deleting the environment when a pull request is merged.
Before you begin
To manage source integrations, you need to be a project admin. You also need a Bitbucket Cloud or Bitbucket Server repository with working code.Bitbucket Cloud
1. Create an OAuth consumer
To integrate your Upsun project with an existing Bitbucket Cloud repository, create an OAuth consumer:Be sure to define the above as a private consumer by checking the This is a private consumer box.
http://localhost.
Copy the Key and Secret for your consumer.
2. Enable the Cloud integration
To enable the integration, use either the CLI or the Console.- Using the CLI
- In the Console
Run the following command:
PROJECT_IDis the ID of your Upsun project.OWNER/REPOSITORYis the name of your repository in Bitbucket.CONSUMER_KEYis the key of the OAuth consumer you created.CONSUMER_SECRETis the secret of the OAuth consumer you created.
https://bitbucket.org/platformsh/platformsh-docs,
the command is similar to the following:To keep your repository clean and avoid performance issues, make sure you enable both the
fetch-branches and prune-branches options.3. Validate the integration
Verify that your integration is functioning properly using the CLI:Add the webhook manually
If the integration was added with the correct permissions, the necessary webhook is added automatically. If you see a message that the webhook wasn’t added, add one manually. To configure a webhook on a Bitbucket repository, you need to have Admin user permissions.- Get the webhook URL by running this command:
upsun integration:get --property hook_url. - Copy the returned URL.
- Follow the Bitbucket instructions to create a webhook using the URL you copied. Make sure to update the triggers to include all pull request events except comments and approval.
Bitbucket Server
1. Generate a token
To integrate your Upsun project with a repository on a Bitbucket Server instance, you first need to create an access token associated with your account. Generate a token. and give it at least read access to projects and admin access to repositories. Copy the token.2. Enable the Server integration
To enable the integration, use either the CLI or the Console.- Using the CLI
- In the Console
Run the following command:
PROJECT_IDis the ID of your Upsun project.OWNER/REPOSITORYis the name of the repository in Bitbucket server.BITBUCKET_SERVER_ACCESS_TOKENis the token you generated.BITBUCKET_SERVER_URLis the URL for your Bitbucket server.
https://example.com/platformsh/platformsh-docs,
the command is similar to the following:
To keep your repository clean and avoid performance issues,
make sure you enable both the
fetch-branches and prune-branches options.
3. Validate the integration
Verify that your integration is functioning properly using the CLI:Add the webhook manually
If the integration was added with the correct permissions, the necessary webhook is added automatically. If you see a message that the webhook wasn’t added, add one manually. To configure a webhook on a Bitbucket repository, you need to have Admin user permissions.- Get the webhook URL by running this command:
upsun integration:get --property hook_url. - Copy the returned URL.
- Follow the Bitbucket instructions to create a webhook using the URL you copied. Send all events except comments and approval.
Environment parent and status
When a branch is created in Bitbucket, an environment is created in Upsun with the default branch as its parent. It starts as an inactive environment with no data or services. When a pull request is opened in Bitbucket, an environment is created in Upsun with the pull request’s target branch as its parent. It starts as an active environment with a copy of its parent’s data.Source of truth
When you add an integration, your Bitbucket repository is considered to be the source of truth for the project. Your Upsun project is only a mirror of that repository and you can only push commits to Bitbucket. To clone your code, follow these steps:- Using the CLI
- Using Git
Run the following command:
Sync, fetch, and prune
An integration from your source repository to Upsun establishes that:- your source repository is the source of truth, where Git operations occur
- Upsun is a mirror of that repository, provisioning infrastructure according to configuration, and orchestrating environments according to the branch structure of the your source repository repository
fetch-branches (track branches on your source repository) and prune-branches (delete branches that don’t exist on your source repository) by default.
You can change these settings but it is recommended to keep them.
When enabled by default, you are limited by design as to what actions can be performed within the context of an Upsun project with a your source repository integration: