Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5409 from magento/hg-bitbucketrepo
Browse files Browse the repository at this point in the history
fixed repository name and more
  • Loading branch information
dobooth authored Sep 18, 2019
2 parents 5368093 + af0c1ed commit 3a300db
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 152 deletions.
290 changes: 145 additions & 145 deletions guides/v2.2/cloud/integrations/bitbucket-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,216 +22,216 @@ You can configure your Bitbucket repository to automatically build and deploy an

You must clone your {{site.data.var.ece}} project from an existing environment and migrate the project branches to a new, empty Bitbucket repository, preserving the same branch names. It is **critical** to retain an identical Git tree, so that you do not lose any existing environments or branches in your {{site.data.var.ece}} project.

1. From the terminal, log in to your {{site.data.var.ece}} project.
1. From the terminal, log in to your {{site.data.var.ece}} project.

```bash
magento-cloud login
```
```bash
magento-cloud login
```

1. List your projects and copy the project ID.
1. List your projects and copy the project ID.

```bash
magento-cloud project:list
```
```bash
magento-cloud project:list
```

1. Clone the project to your local environment.
1. Clone the project to your local environment.

```bash
magento-cloud project:get <project-ID>
```
```bash
magento-cloud project:get <project-ID>
```

1. Add your Bitbucket repository as a remote.
1. Add your Bitbucket repository as a remote.

```bash
git remote add origin git@bitbucket.org:<user-name>/<repo-name>.git
```
```bash
git remote add origin git@bitbucket.org:<user-name>/<repo-name>.git
```

1. Delete the default `magento` remote.
1. Delete the default `magento` remote.

```bash
git remote remove magento
```
```bash
git remote remove magento
```

1. Verify that you added the Bitbucket remote correctly.
1. Verify that you added the Bitbucket remote correctly.

```bash
git remote -v
```
```bash
git remote -v
```

You should see the following:
You should see the following:

```terminal
origin git@bitbucket.org:<user-name>/<repo-name>.git (fetch)
origin git@bitbucket.org:<user-name>/<repo-name>.git (push)
```
{: .no-copy}
```terminal
origin git@bitbucket.org:<user-name>/<repo-name>.git (fetch)
origin git@bitbucket.org:<user-name>/<repo-name>.git (push)
```
{: .no-copy}

1. Push the project files to your new Bitbucket repository. Remember to keep all branch names the same.
1. Push the project files to your new Bitbucket repository. Remember to keep all branch names the same.

```bash
git push -u origin master
```
```bash
git push -u origin master
```

If you are starting with a new Bitbucket repository, you may have to use the `-f` option, because the remote repository does not match your local copy.
If you are starting with a new Bitbucket repository, you may have to use the `-f` option, because the remote repository does not match your local copy.

1. Verify that your Bitbucket repository contains all of your project files.
1. Verify that your Bitbucket repository contains all of your project files.

## Create an OAuth consumer

The Bitbucket integration requires an [OAuth consumer](https://confluence.atlassian.com/x/pwIwDg). You need the OAuth `key` and `secret` from this consumer to complete the next section.

#### To create an OAuth consumer in Bitbucket:

1. Log in to your [Bitbucket](https://bitbucket.org/account/signin/) account.
1. Log in to your [Bitbucket](https://bitbucket.org/account/signin/) account.

1. Click **Settings** > **Access Management** > **OAuth**.
1. Click **Settings** > **Access Management** > **OAuth**.

1. Click **Add consumer** and configure it as follows:
1. Click **Add consumer** and configure it as follows:

![Bitbucket OAuth consumer configuration]({{ site.baseurl }}/common/images/cloud_oauth_consumer_config.png){: width="700px"}
![Bitbucket OAuth consumer configuration]({{ site.baseurl }}/common/images/cloud_oauth_consumer_config.png){: width="700px"}

{: .bs-callout .bs-callout-warning}
A valid **Callback URL** is not required, but you must enter a value in this field to successfully complete the integration.
{:.bs-callout-warning}
A valid **Callback URL** is not required, but you must enter a value in this field to successfully complete the integration.

1. Click **Save**.
1. Click **Save**.

1. Click the consumer **Name** to reveal your OAuth `key` and `secret`.
1. Click the consumer **Name** to reveal your OAuth `key` and `secret`.

1. Copy your OAuth `key` and `secret` for configuring the integration.
1. Copy your OAuth `key` and `secret` for configuring the integration.

## Configure the integration

1. From the terminal, navigate to your {{site.data.var.ece}} project.
1. From the terminal, navigate to your {{site.data.var.ece}} project.

1. Create a temporary file called `bitbucket.json` and add the following, replacing the variables in angle brackets with your values:
1. Create a temporary file called `bitbucket.json` and add the following, replacing the variables in angle brackets with your values:

```json
{
"type": "bitbucket",
"repository": "<bitbucket-user-name/bitbucket-repo-name>",
"app_credentials": {
"key": "<oauth-consumer-key>",
"secret": "<oauth-consumer-secret>"
},
"prune_branches": true,
"fetch_branches": true,
"build_pull_requests": true,
"resync_pull_requests": true
}
```
```json
{
"type": "bitbucket",
"repository": "<bitbucket-user-name/bitbucket-repo-name>",
"app_credentials": {
"key": "<oauth-consumer-key>",
"secret": "<oauth-consumer-secret>"
},
"prune_branches": true,
"fetch_branches": true,
"build_pull_requests": true,
"resync_pull_requests": true
}
```

{: .bs-callout .bs-callout-tip}
Be sure to use the name of your Bitbucket repository and not the URL. The integration fails if you use a URL.
{:.bs-callout-tip}
Be sure to use the name of your Bitbucket repository and not the URL. The integration fails if you use a URL.

1. Add the integration to your project using the `magento-cloud` CLI tool.
1. Add the integration to your project using the `magento-cloud` CLI tool.

{: .bs-callout .bs-callout-warning}
The following command overwrites _all_ code in your {{site.data.var.ece}} project with code from your Bitbucket repository. This includes all branches, including the Production branch. This action happens instantly and cannot be undone. As a best practice, it is very important to clone all of your branches from your {{site.data.var.ece}} project and push them to your Bitbucket repository **before** adding the Bitbucket integration.
{:.bs-callout-warning}
The following command overwrites _all_ code in your {{site.data.var.ece}} project with code from your Bitbucket repository. This includes all branches, including the Production branch. This action happens instantly and cannot be undone. As a best practice, it is very important to clone all of your branches from your {{site.data.var.ece}} project and push them to your Bitbucket repository **before** adding the Bitbucket integration.

```bash
magento-cloud project:curl -p '<project-ID>' /integrations -i -X POST -d "$(< bitbucket.json)"
```
```bash
magento-cloud project:curl -p '<project-ID>' /integrations -i -X POST -d "$(< bitbucket.json)"
```

This returns a long HTTP response with headers. A successful integration returns a 200 or 201 status code. A status of 400 or above indicates that an error occurred.
This returns a long HTTP response with headers. A successful integration returns a 200 or 201 status code. A status of 400 or above indicates that an error occurred.

1. Delete the temporary `bitbucket.json` file.
1. Delete the temporary `bitbucket.json` file.

1. Verify the project integration.
1. Verify the project integration.

```bash
magento-cloud integrations -p '<project-ID>'
```
```bash
magento-cloud integrations -p '<project-ID>'
```

```terminal
+----------+-----------+--------------------------------------------------------------------------------+
| ID | Type | Summary |
+----------+-----------+--------------------------------------------------------------------------------+
| <int-id> | bitbucket | Repository: bitbucket_Account/magento-int.git |
| | | Hook URL: |
| | | https://magento-url.cloud/api/projects/<project-id>/integrations/<int-id>/hook |
+----------+-----------+--------------------------------------------------------------------------------+
```
{: .no-copy}
```terminal
+----------+-----------+--------------------------------------------------------------------------------+
| ID | Type | Summary |
+----------+-----------+--------------------------------------------------------------------------------+
| <int-id> | bitbucket | Repository: bitbucket_Account/magento-int |
| | | Hook URL: |
| | | https://magento-url.cloud/api/projects/<project-id>/integrations/<int-id>/hook |
+----------+-----------+--------------------------------------------------------------------------------+
```
{: .no-copy}

Make a note of the **Hook URL** to configure a webhook in BitBucket.
Make a note of the **Hook URL** to configure a webhook in BitBucket.

### Add a webhook in BitBucket

In order to communicate events—such as a push—with your Cloud Git server, you need to create a webhook for your BitBucket repository.

1. Log in to your [Bitbucket](https://bitbucket.org/account/signin/) account.
1. Log in to your [Bitbucket](https://bitbucket.org/account/signin/) account.

1. Click **Repositories** and select your project.
1. Click **Repositories** and select your project.

1. Click **Settings** > **Workflow** > **Webhooks**.
1. Click **Settings** > **Workflow** > **Webhooks**.

1. Click **Add webhook**.
1. Click **Add webhook**.

1. In the _Add new webhook_ view, edit the following fields:
1. In the _Add new webhook_ view, edit the following fields:

- **Title**: Magento Cloud Integration
- **URL**: Use the Hook URL from your `magento-cloud` integration list
- **Triggers**: The default is a basic _Repository push_
- **Title**: Magento Cloud Integration
- **URL**: Use the Hook URL from your `magento-cloud` integration list
- **Triggers**: The default is a basic _Repository push_

1. Click **Save**.
1. Click **Save**.

### Test the integration

After configuring the Bitbucket integration, test it by pushing a simple change to your Bitbucket repository.

1. Create a test file.
1. Create a test file.

```bash
touch test.md
```
```bash
touch test.md
```

1. Commit and push the change to your Bitbucket repository.
1. Commit and push the change to your Bitbucket repository.

```
git add . && git commit -m "Testing Bitbucket integration" && git push
```
```bash
git add . && git commit -m "Testing Bitbucket integration" && git push
```

1. Log in to the [Project Web Interface]({{ page.baseurl }}/cloud/project/project-webint-basic.html) and verify that your commit message is displayed and your project deploying.
1. Log in to the [Project Web Interface]({{ page.baseurl }}/cloud/project/project-webint-basic.html) and verify that your commit message is displayed and your project deploying.

![Testing the Bitbucket integration]({{ site.baseurl }}/common/images/cloud_test_bitbucket_integration.png)
![Testing the Bitbucket integration]({{ site.baseurl }}/common/images/cloud_test_bitbucket_integration.png)

## Create a new Cloud branch

The Bitbucket integration cannot activate new environments in your {{site.data.var.ece}} project. If you create an environment with Bitbucket, you must activate the environment manually. To avoid this extra step, it is best practice to create environments using the `magento-cloud` CLI tool or the Project Web UI.

#### To activate a branch created with Bitbucket:

1. Use the magento-cloud CLI to push the branch.

```bash
magento-cloud environment:push from-bitbucket
```

```terminal
Pushing from-bitbucket to the new environment from-bitbucket
Activate from-bitbucket after pushing? [Y/n] y
Parent environment [master]: integration
--- (Validation and activation messages)
```
{: .no-copy}

1. Verify the environment is active.

```bash
magento-cloud environment:list
```

```terminal
Your environments are:
+---------------------+----------------+--------+
| ID          | Name        | Status |
+---------------------+----------------+--------+
| master      | Master      | Active |
| integration | integration | Active |
|    from-bitbucket * | from-bitbucket | Active |
+---------------------+----------------+--------+
* - Indicates the current environment
```
1. Use the magento-cloud CLI to push the branch.

```bash
magento-cloud environment:push from-bitbucket
```

```terminal
Pushing from-bitbucket to the new environment from-bitbucket
Activate from-bitbucket after pushing? [Y/n] y
Parent environment [master]: integration
--- (Validation and activation messages)
```
{: .no-copy}

1. Verify the environment is active.

```bash
magento-cloud environment:list
```

```terminal
Your environments are:
+---------------------+----------------+--------+
| ID          | Name        | Status |
+---------------------+----------------+--------+
| master      | Master      | Active |
| integration | integration | Active |
|    from-bitbucket * | from-bitbucket | Active |
+---------------------+----------------+--------+
* - Indicates the current environment
```

After you create a new environment, you can push the corresponding branch to your remote Bitbucket repository using regular Git commands. Subsequent changes to your branch in Bitbucket automatically build and deploy the environment.

Expand All @@ -241,18 +241,18 @@ You can safely remove the Bitbucket integration from your project without affect

#### To remove the Bitbucket integration:

1. From the terminal, log in to your {{site.data.var.ece}} project.
1. From the terminal, log in to your {{site.data.var.ece}} project.

1. List your integrations. You need the Bitbucket integration ID to complete the next step.
1. List your integrations. You need the Bitbucket integration ID to complete the next step.

```bash
magento-cloud integration:list
```
```bash
magento-cloud integration:list
```

1. Delete the integration.
1. Delete the integration.

```bash
magento-cloud integration:delete <project-ID>
```
```bash
magento-cloud integration:delete <project-ID>
```

Also, you can remove the Bitbucket integration by logging in to your Bitbucket account and revoking the OAuth grant on the account _Settings_ page.
Loading

0 comments on commit 3a300db

Please sign in to comment.