Bitbucket Server Integration



Bitbucket Server is only supported on env0 Organizations signed up for our Self-Hosted Agent.

Initial Bitbucket Server Setup

For env0 to be able to clone your code and post back commit statuses when running Plan on Pull Request you need to provide it with an access token with write permissions.

This only needs to be done once for your Organization.

  1. Create a Personal access token on your Bitbucket Server.
  • We recommend creating the token for a bot user - as that is the user that will post back commit statuses and comments.
  • The user must have access to each repository you would like to be able to use with env0.
  • The token must have “Repository write” permissions.
  1. In the AWS account which you have installed the env0 Self-Hosted Agent, go to AWS Secrets Manager and create a new Plaintext secret.
  2. In the Plaintext value paste the access token for your Bitbucket server in the following format: username:token where username is the username of the user you have used to create the token, and token being the value copied from step 1.
  3. Name the secret as env0/bitbucket-server-credentials.

New Template

  1. Click CREATE NEW TEMPLATE on the top right corner in the Templates screen.
  2. Pick your template type, enter a name for the template and then click NEXT
  3. Click the Bitbucket Server button.
  4. Enter your repository's HTTPs URL.
  5. If you would like to pull the code from a specific revision or branch, enter that in the Revision field. Leaving this field empty will use your default branch, which is usually “master”/"main".
  6. Enter the folder your IaC files are located in under Terraform Folder or Terragrunt Folder. If your IaC files are at the root of the repository, leave this empty.
  7. If you haven't configured env0 Webhooks on this repository before, copy the Webhook URL and Webhook Secret values and paste them on your Bitbucket Server repository's settings page. More on that here.
  8. Click NEXT to proceed to the variables section
  9. Add environment and IaC variables that you'd like to be used during deployment, and then click on NEXT to go to the final "Projects" section
  10. Pick the projects that you'd like to have access to deploy this template, and then click on DONE to create the template.
  11. Pick the projects that you'd like to have access to deploy this template, and then click on DONE to create the template.
BBS template creationBBS template creation

BBS template creation

Webhooks Integration

Adding Webhooks are required in order to support Continuous Deployment and our Plan on Pull Request features on Bitbucket Server.

  1. Open your repository page in Bitbucket Server.
  2. Click on the settings icon.
  3. Enter to the Webhooks page.
  4. Click on the "Create webhook" button.
  5. Give it a name, like "env0 integration".
  6. Copy & Paste the URL and Secret values from the en0 Template creation page.
  7. Mark ONLY Repository Push and Pull Request Opened, as shown in the picture below.
  8. Make sure the webhook is marked as Active.
  9. Click on the Create button.
BBS webhook creationBBS webhook creation

BBS webhook creation

Existing Template

If you would like to integrate an existing template with Bitbucket Server:

  1. Go to the Templates screen, and click on Settings for the template you would like to integrate with Bitbucket Server.
  2. Click on the VCS step. From there you can click on the Bitbucket Server button, and integrate with Bitbucket Server as you would for a new template.

Did this page help you?